blob: 0095cf81542481c309f42031ed85c9a4b7dff698 [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
Marc Slemko6f038a72006-08-03 18:58:09 +00006#include <boost/shared_ptr.hpp>
7
Marc Slemko66949872006-07-15 01:52:39 +00008namespace facebook { namespace thrift { namespace concurrency {
9
Marc Slemko6f038a72006-08-03 18:58:09 +000010using namespace boost;
11
Marc Slemko66949872006-07-15 01:52:39 +000012/** A thread factory to create posix threads
13
Marc Slemko0e53ccd2006-07-17 23:51:05 +000014 @author marc
15 @version $Id:$ */
Marc Slemko66949872006-07-15 01:52:39 +000016
17class 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 Slemko6f038a72006-08-03 18:58:09 +000050 shared_ptr<Thread> newThread(shared_ptr<Runnable> runnable) const;
Marc Slemko66949872006-07-15 01:52:39 +000051
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 Slemko6f038a72006-08-03 18:58:09 +000076 shared_ptr<Impl> _impl;
Marc Slemko66949872006-07-15 01:52:39 +000077};
78
79}}} // facebook::thrift::concurrency
80
81#endif // !defined(_concurrency_PosixThreadFactory_h_)