| 31 | class ThreadArg; |
| 32 | |
| 33 | class ThreadPoolManager { |
| 34 | |
| 35 | public: |
| 36 | enum Flags { |
| 37 | VERBOSE = 1 |
| 38 | }; |
| 39 | |
| 40 | static void init(unsigned int max_threads, unsigned int flags = 0) { |
| 41 | assert(instance == NULL); |
| 42 | instance = new ThreadPoolManager(max_threads, flags); |
| 43 | } |
| 44 | |
| 45 | static ThreadPoolManager* getInstance() { |
| 46 | return instance; |
| 47 | } |
| 48 | |
| 49 | bool reserveOneThread(); |
| 50 | void releaseOneThread(); |
| 51 | unsigned int getMaxThreads() const {return max_threads;} |
| 52 | unsigned int getFlags() const {return flags;} |
| 53 | |
| 54 | bool isMainThread() const {return pthread_self() == main_pthread;} |
| 55 | |
| 56 | ThreadPool* newThreadPool(const std::string& name); |
| 57 | |
| 58 | void lock() const; |
| 59 | void unlock() const; |
| 60 | |
| 61 | private: |
| 62 | static ThreadPoolManager* instance; |
| 63 | |
| 64 | unsigned int max_threads; |
| 65 | unsigned int flags; |
| 66 | unsigned int available_threads; |
| 67 | mutable pthread_mutex_t mp; |
| 68 | pthread_t main_pthread; |
| 69 | |
| 70 | ThreadPoolManager(unsigned int max_threads, unsigned int flags = 0); |
| 71 | }; |
| 72 | |
| 73 | class Thread { |
| 74 | static const int WAIT_USECONDS = 50000; |
nothing calls this directly
no outgoing calls
no test coverage detected