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_WIN_H_
12#define WEBRTC_SYSTEM_WRAPPERS_SOURCE_THREAD_WIN_H_
13
14#include "webrtc/system_wrappers/interface/thread_wrapper.h"
15
16#include <windows.h>
17
18#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
19#include "webrtc/system_wrappers/interface/event_wrapper.h"
20
21namespace webrtc {
22
23class ThreadWindows : public ThreadWrapper {
24 public:
25  ThreadWindows(ThreadRunFunction func, ThreadObj obj, ThreadPriority prio,
26                const char* thread_name);
27  virtual ~ThreadWindows();
28
29  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();
34
35  static unsigned int WINAPI StartThread(LPVOID lp_parameter);
36
37 protected:
38  virtual void Run();
39
40 private:
41  ThreadRunFunction    run_function_;
42  ThreadObj            obj_;
43
44  bool                    alive_;
45  bool                    dead_;
46
47  // 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_;
55
56  HANDLE                  thread_;
57  unsigned int            id_;
58  char                    name_[kThreadMaxNameLength];
59  bool                    set_thread_name_;
60
61};
62
63}  // namespace webrtc
64
65#endif  // WEBRTC_SYSTEM_WRAPPERS_SOURCE_THREAD_WIN_H_
66