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