blob: befb4feba8650041ece93771395f84aa5d220605 [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
8/** Minimal runnable class. More or less analogous to java.lang.Runnable. */
9
10class Runnable {
11
12 public:
13
14 virtual ~Runnable() {};
15
16 virtual void run() = 0;
17};
18
19/** 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
20 (minus all the thread group, priority, mode and other baggage, since that is difficult to abstract across platforms and is left for platform-specific
21 ThreadFactory implemtations to deal with - @see facebook::thrift::concurrency::ThreadFactory) */
22
23
24class Thread {
25
26 public:
27
28 virtual ~Thread() {};
29
30 /** Starts the thread. Does platform specific thread creation and configuration then invokes the run method of the Runnable object bound to this
31 thread. */
32
33 virtual void start() = 0;
34
35 /** Join this thread
36
37 Current thread blocks until this target thread completes. */
38
39 virtual void join() = 0;
40
41 /** Gets the runnable object this thread is hosting */
42
43 virtual const Runnable* runnable() const = 0;
44};
45
46/** Factory to create platform-specific thread object and bind them to Runnable object for execution */
47
48class ThreadFactory {
49
50 public:
51
52 virtual ~ThreadFactory() {}
53
54 virtual Thread* newThread(Runnable* runnable) const = 0;
55};
56
57}}} // facebook::thrift::concurrency
58
59#endif // !defined(_concurrency_Thread_h_)