niklase@google.com | f0779a2 | 2011-05-30 11:39:38 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #ifndef WEBRTC_SYSTEM_WRAPPERS_SOURCE_THREAD_LINUX_H_ |
| 12 | #define WEBRTC_SYSTEM_WRAPPERS_SOURCE_THREAD_LINUX_H_ |
| 13 | |
| 14 | #include "thread_wrapper.h" |
| 15 | #include <pthread.h> |
| 16 | |
| 17 | namespace webrtc { |
| 18 | class EventWrapper; |
| 19 | |
| 20 | class ThreadLinux : public ThreadWrapper |
| 21 | { |
| 22 | public: |
| 23 | static ThreadWrapper* Create(ThreadRunFunction func, ThreadObj obj, |
| 24 | ThreadPriority prio, const char* threadName); |
| 25 | |
| 26 | ThreadLinux(ThreadRunFunction func, ThreadObj obj, ThreadPriority prio, |
| 27 | const char* threadName); |
| 28 | ~ThreadLinux(); |
| 29 | |
| 30 | // From ThreadWrapper |
| 31 | virtual void SetNotAlive(); |
| 32 | virtual bool Start(unsigned int& id); |
| 33 | // Not implemented on Mac |
| 34 | virtual bool SetAffinity(const int* processorNumbers, |
| 35 | unsigned int amountOfProcessors); |
| 36 | virtual bool Stop(); |
| 37 | virtual bool Shutdown(); |
| 38 | |
| 39 | void Run(); |
| 40 | |
| 41 | private: |
| 42 | int Construct(); |
| 43 | |
| 44 | private: |
| 45 | // processing function |
| 46 | ThreadRunFunction _runFunction; |
| 47 | ThreadObj _obj; |
| 48 | |
| 49 | // internal state |
| 50 | bool _alive; |
| 51 | bool _dead; |
| 52 | ThreadPriority _prio; |
| 53 | EventWrapper* _event; |
| 54 | |
| 55 | // zero-terminated thread name string |
| 56 | char _name[kThreadMaxNameLength]; |
| 57 | bool _setThreadName; |
| 58 | |
| 59 | // handle to thread |
| 60 | pthread_attr_t _attr; |
| 61 | pthread_t _thread; |
| 62 | #ifdef WEBRTC_LINUX |
| 63 | pid_t _linuxPid; |
| 64 | #endif |
| 65 | |
| 66 | }; |
| 67 | } // namespace webrtc |
| 68 | |
| 69 | #endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_THREAD_LINUX_H_ |