blob: 2705f77850eeb301ca1fd6edf9c4e21866b456ce [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
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.orgec9c9422013-01-02 08:45:03 +000011#ifndef WEBRTC_SYSTEM_WRAPPERS_SOURCE_THREAD_WIN_H_
12#define WEBRTC_SYSTEM_WRAPPERS_SOURCE_THREAD_WIN_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000014#include "webrtc/system_wrappers/interface/thread_wrapper.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000015
16#include <windows.h>
17
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000018#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
19#include "webrtc/system_wrappers/interface/event_wrapper.h"
20
niklase@google.com470e71d2011-07-07 08:21:25 +000021namespace webrtc {
22
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000023class ThreadWindows : public ThreadWrapper {
24 public:
25 ThreadWindows(ThreadRunFunction func, ThreadObj obj, ThreadPriority prio,
26 const char* thread_name);
27 virtual ~ThreadWindows();
niklase@google.com470e71d2011-07-07 08:21:25 +000028
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000029 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.com470e71d2011-07-07 08:21:25 +000034
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000035 static unsigned int WINAPI StartThread(LPVOID lp_parameter);
niklase@google.com470e71d2011-07-07 08:21:25 +000036
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000037 protected:
38 virtual void Run();
niklase@google.com470e71d2011-07-07 08:21:25 +000039
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000040 private:
41 ThreadRunFunction run_function_;
42 ThreadObj obj_;
niklase@google.com470e71d2011-07-07 08:21:25 +000043
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000044 bool alive_;
45 bool dead_;
niklase@google.com470e71d2011-07-07 08:21:25 +000046
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000047 // 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.com470e71d2011-07-07 08:21:25 +000055
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000056 HANDLE thread_;
57 unsigned int id_;
58 char name_[kThreadMaxNameLength];
59 bool set_thread_name_;
niklase@google.com470e71d2011-07-07 08:21:25 +000060
61};
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000062
niklase@google.com470e71d2011-07-07 08:21:25 +000063} // namespace webrtc
64
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000065#endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_THREAD_WIN_H_