blob: 0da8a53a0dff7a251d509cd0df8d26ea79a5b0f2 [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;
niklase@google.com470e71d2011-07-07 08:21:25 +000030
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000031 protected:
tommi@webrtc.orgaef07792015-01-30 15:06:10 +000032 void Run();
niklase@google.com470e71d2011-07-07 08:21:25 +000033
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000034 private:
tommi@webrtc.orgaef07792015-01-30 15:06:10 +000035 static DWORD WINAPI StartThread(void* param);
niklase@google.com470e71d2011-07-07 08:21:25 +000036
tommi@webrtc.orgaef07792015-01-30 15:06:10 +000037 ThreadRunFunction const run_function_;
38 void* const obj_;
tommi@webrtc.org9d94a0c2015-02-11 14:16:08 +000039 bool stop_;
tommi@webrtc.orgaef07792015-01-30 15:06:10 +000040 // TODO(tommi): Consider having a SetPriority method instead of this variable.
41 ThreadPriority prio_;
42 HANDLE thread_;
43 const std::string name_;
44 rtc::ThreadChecker main_thread_;
niklase@google.com470e71d2011-07-07 08:21:25 +000045};
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000046
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +000047} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +000048
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000049#endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_THREAD_WIN_H_