blob: 8237091ae325c9d5bb982728fa281f75c1f17c0d [file] [log] [blame]
Marc Slemko66949872006-07-15 01:52:39 +00001#if !defined(_concurrency_Thread_h_)
2#define _concurrency_Thread_h_ 1
3
4namespace facebook { namespace thrift { namespace concurrency {
5
6class Thread;
7
Marc Slemko0e53ccd2006-07-17 23:51:05 +00008/** Minimal runnable class. More or less analogous to java.lang.Runnable.
9
10 @author marc
11 @version $Id:$ */
Marc Slemko66949872006-07-15 01:52:39 +000012
13class Runnable {
14
15 public:
16
17 virtual ~Runnable() {};
18
19 virtual void run() = 0;
20};
21
22/** Minimal thread class. Returned by thread factory bound to a Runnable object and ready to start execution. More or less analogous to java.lang.Thread
23 (minus all the thread group, priority, mode and other baggage, since that is difficult to abstract across platforms and is left for platform-specific
24 ThreadFactory implemtations to deal with - @see facebook::thrift::concurrency::ThreadFactory) */
25
26
27class Thread {
28
29 public:
30
31 virtual ~Thread() {};
32
33 /** Starts the thread. Does platform specific thread creation and configuration then invokes the run method of the Runnable object bound to this
34 thread. */
35
36 virtual void start() = 0;
37
38 /** Join this thread
39
40 Current thread blocks until this target thread completes. */
41
42 virtual void join() = 0;
43
44 /** Gets the runnable object this thread is hosting */
45
Marc Slemkod466b212006-07-20 00:04:18 +000046 virtual Runnable* runnable() const = 0;
Marc Slemko66949872006-07-15 01:52:39 +000047};
48
49/** Factory to create platform-specific thread object and bind them to Runnable object for execution */
50
51class ThreadFactory {
52
53 public:
54
55 virtual ~ThreadFactory() {}
56
57 virtual Thread* newThread(Runnable* runnable) const = 0;
58};
59
60}}} // facebook::thrift::concurrency
61
62#endif // !defined(_concurrency_Thread_h_)