Elm  1.0
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Thread.h
1 /*
2  * $Id$
3  * System class interface
4  *
5  * This file is part of OTAWA
6  * Copyright (c) 2011, IRIT UPS.
7  *
8  * OTAWA is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * OTAWA is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with OTAWA; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 #ifndef ELM_SYSTEM_THREAD_H_
23 #define ELM_SYSTEM_THREAD_H_
24 
25 #include <elm/sys/SystemException.h>
26 #include <elm/util/MessageException.h>
27 
28 namespace elm { namespace sys {
29 
30 // pre-declaration
31 class Thread;
32 
33 // ThreadException class
35 public:
36  inline ThreadException(const string& message): MessageException(message) { }
37 };
38 
39 
40 // Runnable class
41 class Runnable {
42 public:
43  virtual ~Runnable(void);
44  virtual void run(void) = 0;
45 protected:
46  void stop(void);
47  inline Thread *current(void) const { return thr; }
48 private:
49  Thread *thr;
50 };
51 
52 // Thread class
53 class Thread {
54  friend class Runnable;
55 public:
56  virtual ~Thread(void);
57  static Thread *make(Runnable& runnable);
58  virtual void start(void) throw(ThreadException) = 0;
59  virtual void join(void) throw(ThreadException) = 0;
60  virtual void kill(void) throw(ThreadException) = 0;
61  virtual bool isRunning(void) = 0;
62 
63 protected:
65  Thread(Runnable& runnable);
66  virtual void stop(void) = 0;
67 };
68 
69 
70 class Mutex {
71 public:
72  static Mutex *make(void) throw(SystemException);
73  virtual ~Mutex(void);
74  virtual void lock(void) throw(SystemException) = 0;
75  virtual void unlock(void) throw(SystemException) = 0;
76  virtual bool tryLock(void) throw(SystemException) = 0;
77 };
78 
79 } } // elm::sys
80 
81 #endif /* ELM_SYSTEM_THREAD_H_ */
virtual ~Thread(void)
Definition: system_Thread.cpp:80
Definition: Thread.h:70
ThreadException(const string &message)
Definition: Thread.h:36
virtual bool isRunning(void)=0
virtual void kill(void)=0
Definition: Thread.h:53
Definition: SystemException.h:29
void stop(void)
Definition: system_Thread.cpp:66
static Thread * make(Runnable &runnable)
Definition: system_Thread.cpp:321
virtual void run(void)=0
virtual ~Runnable(void)
Definition: system_Thread.cpp:59
virtual void start(void)=0
virtual void join(void)=0
Definition: Thread.h:34
Thread * current(void) const
Definition: Thread.h:47
Runnable & _runnable
Definition: Thread.h:64
virtual String message(void)
Definition: util_MessageException.cpp:50
Definition: Thread.h:41
Definition: MessageException.h:30
virtual void stop(void)=0