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