Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 1 | #if !defined(_concurrency_PosixThreadFactory_h_) |
| 2 | #define _concurrency_PosixThreadFactory_h_ 1 |
| 3 | |
| 4 | #include "Thread.h" |
| 5 | |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 6 | #include <boost/shared_ptr.hpp> |
| 7 | |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 8 | namespace facebook { namespace thrift { namespace concurrency { |
| 9 | |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 10 | using namespace boost; |
| 11 | |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 12 | /** A thread factory to create posix threads |
| 13 | |
Marc Slemko | 0e53ccd | 2006-07-17 23:51:05 +0000 | [diff] [blame] | 14 | @author marc |
| 15 | @version $Id:$ */ |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 16 | |
| 17 | class PosixThreadFactory : public ThreadFactory { |
| 18 | |
| 19 | public: |
| 20 | |
| 21 | /** POSIX Thread scheduler policies */ |
| 22 | |
| 23 | enum POLICY { |
| 24 | OTHER, |
| 25 | FIFO, |
| 26 | ROUND_ROBIN |
| 27 | }; |
| 28 | |
| 29 | /** POSIX Thread scheduler relative priorities, |
| 30 | |
| 31 | Absolute priority is determined by scheduler policy and OS. This enumeration specifies relative priorities such that one can |
| 32 | specify a priority withing a giving scheduler policy without knowing the absolute value of the priority. */ |
| 33 | |
| 34 | enum PRIORITY { |
| 35 | LOWEST = 0, |
| 36 | LOWER = 1, |
| 37 | LOW = 2, |
| 38 | NORMAL = 3, |
| 39 | HIGH = 4, |
| 40 | HIGHER = 5, |
| 41 | HIGHEST = 6, |
| 42 | INCREMENT = 7, |
| 43 | DECREMENT = 8 |
| 44 | }; |
| 45 | |
| 46 | PosixThreadFactory(POLICY policy=ROUND_ROBIN, PRIORITY priority=NORMAL, int stackSize=1, bool detached=false); |
| 47 | |
| 48 | // From ThreadFactory; |
| 49 | |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 50 | shared_ptr<Thread> newThread(shared_ptr<Runnable> runnable) const; |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 51 | |
| 52 | /** Sets stack size for created threads |
| 53 | |
| 54 | @param value size in megabytes */ |
| 55 | |
| 56 | virtual void stackSize(int value); |
| 57 | |
| 58 | /** Gets stack size for created threads |
| 59 | |
| 60 | @return int size in megabytes */ |
| 61 | |
| 62 | virtual int stackSize() const; |
| 63 | |
| 64 | /** Sets priority relative to current policy */ |
| 65 | |
| 66 | virtual void priority(PRIORITY priority); |
| 67 | |
| 68 | /** Gets priority relative to current policy */ |
| 69 | |
| 70 | virtual PRIORITY priority() const; |
| 71 | |
| 72 | private: |
| 73 | |
| 74 | class Impl; |
| 75 | |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 76 | shared_ptr<Impl> _impl; |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | }}} // facebook::thrift::concurrency |
| 80 | |
| 81 | #endif // !defined(_concurrency_PosixThreadFactory_h_) |