blob: 2d8fa9226007c81f86d36844cab8abcd7e9f5088 [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
tommi@webrtc.orgaef07792015-01-30 15:06:10 +000018#include "webrtc/base/thread_checker.h"
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000019
niklase@google.com470e71d2011-07-07 08:21:25 +000020namespace webrtc {
21
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000022class ThreadWindows : public ThreadWrapper {
23 public:
tommi@webrtc.orgaef07792015-01-30 15:06:10 +000024 ThreadWindows(ThreadRunFunction func, void* obj, ThreadPriority prio,
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000025 const char* thread_name);
tommi@webrtc.orgaef07792015-01-30 15:06:10 +000026 ~ThreadWindows() override;
niklase@google.com470e71d2011-07-07 08:21:25 +000027
tommi@webrtc.orgaef07792015-01-30 15:06:10 +000028 bool Start(unsigned int& id) override;
29 bool Stop() override;
30 void SetNotAlive() override;
niklase@google.com470e71d2011-07-07 08:21:25 +000031
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000032 protected:
tommi@webrtc.orgaef07792015-01-30 15:06:10 +000033 void Run();
niklase@google.com470e71d2011-07-07 08:21:25 +000034
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000035 private:
tommi@webrtc.orgaef07792015-01-30 15:06:10 +000036 static DWORD WINAPI StartThread(void* param);
niklase@google.com470e71d2011-07-07 08:21:25 +000037
tommi@webrtc.orgaef07792015-01-30 15:06:10 +000038 ThreadRunFunction const run_function_;
39 void* const obj_;
40 HANDLE event_; // Used to signal stoppage.
41 // TODO(tommi): Consider having a SetPriority method instead of this variable.
42 ThreadPriority prio_;
43 HANDLE thread_;
44 const std::string name_;
45 rtc::ThreadChecker main_thread_;
niklase@google.com470e71d2011-07-07 08:21:25 +000046};
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000047
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +000048} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +000049
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000050#endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_THREAD_WIN_H_