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 | |
phoglund@webrtc.org | ec9c942 | 2013-01-02 08:45:03 +0000 | [diff] [blame^] | 11 | #ifndef WEBRTC_SYSTEM_WRAPPERS_SOURCE_THREAD_WIN_H_ |
| 12 | #define WEBRTC_SYSTEM_WRAPPERS_SOURCE_THREAD_WIN_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | |
phoglund@webrtc.org | ec9c942 | 2013-01-02 08:45:03 +0000 | [diff] [blame^] | 14 | #include "webrtc/system_wrappers/interface/thread_wrapper.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 15 | |
| 16 | #include <windows.h> |
| 17 | |
phoglund@webrtc.org | ec9c942 | 2013-01-02 08:45:03 +0000 | [diff] [blame^] | 18 | #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" |
| 19 | #include "webrtc/system_wrappers/interface/event_wrapper.h" |
| 20 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 21 | namespace webrtc { |
| 22 | |
phoglund@webrtc.org | ec9c942 | 2013-01-02 08:45:03 +0000 | [diff] [blame^] | 23 | class ThreadWindows : public ThreadWrapper { |
| 24 | public: |
| 25 | ThreadWindows(ThreadRunFunction func, ThreadObj obj, ThreadPriority prio, |
| 26 | const char* thread_name); |
| 27 | virtual ~ThreadWindows(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 28 | |
phoglund@webrtc.org | ec9c942 | 2013-01-02 08:45:03 +0000 | [diff] [blame^] | 29 | virtual bool Start(unsigned int& id); |
| 30 | bool SetAffinity(const int* processor_numbers, |
| 31 | const unsigned int amount_of_processors); |
| 32 | virtual bool Stop(); |
| 33 | virtual void SetNotAlive(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 34 | |
phoglund@webrtc.org | ec9c942 | 2013-01-02 08:45:03 +0000 | [diff] [blame^] | 35 | static unsigned int WINAPI StartThread(LPVOID lp_parameter); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 36 | |
phoglund@webrtc.org | ec9c942 | 2013-01-02 08:45:03 +0000 | [diff] [blame^] | 37 | protected: |
| 38 | virtual void Run(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 39 | |
phoglund@webrtc.org | ec9c942 | 2013-01-02 08:45:03 +0000 | [diff] [blame^] | 40 | private: |
| 41 | ThreadRunFunction run_function_; |
| 42 | ThreadObj obj_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 43 | |
phoglund@webrtc.org | ec9c942 | 2013-01-02 08:45:03 +0000 | [diff] [blame^] | 44 | bool alive_; |
| 45 | bool dead_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 46 | |
phoglund@webrtc.org | ec9c942 | 2013-01-02 08:45:03 +0000 | [diff] [blame^] | 47 | // TODO(hellner) |
| 48 | // do_not_close_handle_ 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 do_not_close_handle_; |
| 52 | ThreadPriority prio_; |
| 53 | EventWrapper* event_; |
| 54 | CriticalSectionWrapper* critsect_stop_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 55 | |
phoglund@webrtc.org | ec9c942 | 2013-01-02 08:45:03 +0000 | [diff] [blame^] | 56 | HANDLE thread_; |
| 57 | unsigned int id_; |
| 58 | char name_[kThreadMaxNameLength]; |
| 59 | bool set_thread_name_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 60 | |
| 61 | }; |
phoglund@webrtc.org | ec9c942 | 2013-01-02 08:45:03 +0000 | [diff] [blame^] | 62 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 63 | } // namespace webrtc |
| 64 | |
phoglund@webrtc.org | ec9c942 | 2013-01-02 08:45:03 +0000 | [diff] [blame^] | 65 | #endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_THREAD_WIN_H_ |