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