niklase@google.com | 470e71d | 2011-07-07 08:21:25 +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_WINDOWS_H_ |
| 12 | #define WEBRTC_SYSTEM_WRAPPERS_SOURCE_THREAD_WINDOWS_H_ |
| 13 | |
| 14 | #include "thread_wrapper.h" |
| 15 | #include "event_wrapper.h" |
| 16 | #include "critical_section_wrapper.h" |
| 17 | |
| 18 | #include <windows.h> |
| 19 | |
| 20 | namespace webrtc { |
| 21 | |
| 22 | class ThreadWindows : public ThreadWrapper |
| 23 | { |
| 24 | public: |
| 25 | ThreadWindows(ThreadRunFunction func, ThreadObj obj, ThreadPriority prio, |
| 26 | const char* threadName); |
| 27 | virtual ~ThreadWindows(); |
| 28 | |
| 29 | virtual bool Start(unsigned int& id); |
| 30 | bool SetAffinity(const int* processorNumbers, |
| 31 | const unsigned int amountOfProcessors); |
| 32 | virtual bool Stop(); |
| 33 | virtual void SetNotAlive(); |
| 34 | |
| 35 | static unsigned int WINAPI StartThread(LPVOID lpParameter); |
| 36 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 37 | protected: |
| 38 | virtual void Run(); |
| 39 | |
| 40 | private: |
| 41 | ThreadRunFunction _runFunction; |
| 42 | ThreadObj _obj; |
| 43 | |
| 44 | bool _alive; |
| 45 | bool _dead; |
| 46 | |
| 47 | // TODO (hellner) |
| 48 | // _doNotCloseHandle member seem pretty redundant. Should be able to remove |
| 49 | // it. Basically it should be fine to reclaim the handle when calling stop |
| 50 | // and in the destructor. |
| 51 | bool _doNotCloseHandle; |
| 52 | ThreadPriority _prio; |
| 53 | EventWrapper* _event; |
| 54 | CriticalSectionWrapper* _critsectStop; |
| 55 | |
| 56 | HANDLE _thread; |
| 57 | unsigned int _id; |
| 58 | char _name[kThreadMaxNameLength]; |
| 59 | bool _setThreadName; |
| 60 | |
| 61 | }; |
| 62 | } // namespace webrtc |
| 63 | |
| 64 | #endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_THREAD_WINDOWS_H_ |