blob: 6fb7d3163fecf1b07c57372d34e5b969571714eb [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);
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000030 virtual bool Stop();
31 virtual void SetNotAlive();
niklase@google.com470e71d2011-07-07 08:21:25 +000032
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000033 static unsigned int WINAPI StartThread(LPVOID lp_parameter);
niklase@google.com470e71d2011-07-07 08:21:25 +000034
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000035 protected:
36 virtual void Run();
niklase@google.com470e71d2011-07-07 08:21:25 +000037
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000038 private:
39 ThreadRunFunction run_function_;
40 ThreadObj obj_;
niklase@google.com470e71d2011-07-07 08:21:25 +000041
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000042 bool alive_;
43 bool dead_;
niklase@google.com470e71d2011-07-07 08:21:25 +000044
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000045 // TODO(hellner)
46 // do_not_close_handle_ member seem pretty redundant. Should be able to remove
47 // it. Basically it should be fine to reclaim the handle when calling stop
48 // and in the destructor.
49 bool do_not_close_handle_;
50 ThreadPriority prio_;
51 EventWrapper* event_;
52 CriticalSectionWrapper* critsect_stop_;
niklase@google.com470e71d2011-07-07 08:21:25 +000053
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000054 HANDLE thread_;
55 unsigned int id_;
56 char name_[kThreadMaxNameLength];
57 bool set_thread_name_;
niklase@google.com470e71d2011-07-07 08:21:25 +000058
59};
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000060
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +000061} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +000062
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000063#endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_THREAD_WIN_H_