Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame^] | 1 | #if !defined(_concurrency_Thread_h_) |
| 2 | #define _concurrency_Thread_h_ 1 |
| 3 | |
| 4 | namespace facebook { namespace thrift { namespace concurrency { |
| 5 | |
| 6 | class Thread; |
| 7 | |
| 8 | /** Minimal runnable class. More or less analogous to java.lang.Runnable. */ |
| 9 | |
| 10 | class 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 | |
| 24 | class 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 | |
| 48 | class 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_) |