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 
37     virtual bool Shutdown();
38 
39 protected:
40     virtual void Run();
41 
42 private:
43     ThreadRunFunction    _runFunction;
44     ThreadObj            _obj;
45 
46     bool                    _alive;
47     bool                    _dead;
48 
49     // TODO (hellner)
50     // _doNotCloseHandle member seem pretty redundant. Should be able to remove
51     // it. Basically it should be fine to reclaim the handle when calling stop
52     // and in the destructor.
53     bool                    _doNotCloseHandle;
54     ThreadPriority          _prio;
55     EventWrapper*           _event;
56     CriticalSectionWrapper* _critsectStop;
57 
58     HANDLE                  _thread;
59     unsigned int            _id;
60     char                    _name[kThreadMaxNameLength];
61     bool                    _setThreadName;
62 
63 };
64 } // namespace webrtc
65 
66 #endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_THREAD_WINDOWS_H_
67