1b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org/*
2b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org *
4b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org *  Use of this source code is governed by a BSD-style license
5b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org *  that can be found in the LICENSE file in the root of the source
6b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org *  tree. An additional intellectual property rights grant can be found
7b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org *  in the file PATENTS.  All contributing project authors may
8b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org *  be found in the AUTHORS file in the root of the source tree.
9b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org */
10b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org
1169e3fb96715bd0b45c1561010fe8eda162ade1adphoglund@webrtc.org#ifndef WEBRTC_SYSTEM_WRAPPERS_SOURCE_THREAD_WIN_H_
1269e3fb96715bd0b45c1561010fe8eda162ade1adphoglund@webrtc.org#define WEBRTC_SYSTEM_WRAPPERS_SOURCE_THREAD_WIN_H_
13b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org
1469e3fb96715bd0b45c1561010fe8eda162ade1adphoglund@webrtc.org#include "webrtc/system_wrappers/interface/thread_wrapper.h"
15b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org
16b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org#include <windows.h>
17b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org
1869e3fb96715bd0b45c1561010fe8eda162ade1adphoglund@webrtc.org#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
1969e3fb96715bd0b45c1561010fe8eda162ade1adphoglund@webrtc.org#include "webrtc/system_wrappers/interface/event_wrapper.h"
2069e3fb96715bd0b45c1561010fe8eda162ade1adphoglund@webrtc.org
21b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.orgnamespace webrtc {
22b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org
2369e3fb96715bd0b45c1561010fe8eda162ade1adphoglund@webrtc.orgclass ThreadWindows : public ThreadWrapper {
2469e3fb96715bd0b45c1561010fe8eda162ade1adphoglund@webrtc.org public:
2569e3fb96715bd0b45c1561010fe8eda162ade1adphoglund@webrtc.org  ThreadWindows(ThreadRunFunction func, ThreadObj obj, ThreadPriority prio,
2669e3fb96715bd0b45c1561010fe8eda162ade1adphoglund@webrtc.org                const char* thread_name);
2769e3fb96715bd0b45c1561010fe8eda162ade1adphoglund@webrtc.org  virtual ~ThreadWindows();
2869e3fb96715bd0b45c1561010fe8eda162ade1adphoglund@webrtc.org
2969e3fb96715bd0b45c1561010fe8eda162ade1adphoglund@webrtc.org  virtual bool Start(unsigned int& id);
3069e3fb96715bd0b45c1561010fe8eda162ade1adphoglund@webrtc.org  bool SetAffinity(const int* processor_numbers,
3169e3fb96715bd0b45c1561010fe8eda162ade1adphoglund@webrtc.org                   const unsigned int amount_of_processors);
3269e3fb96715bd0b45c1561010fe8eda162ade1adphoglund@webrtc.org  virtual bool Stop();
3369e3fb96715bd0b45c1561010fe8eda162ade1adphoglund@webrtc.org  virtual void SetNotAlive();
3469e3fb96715bd0b45c1561010fe8eda162ade1adphoglund@webrtc.org
3569e3fb96715bd0b45c1561010fe8eda162ade1adphoglund@webrtc.org  static unsigned int WINAPI StartThread(LPVOID lp_parameter);
3669e3fb96715bd0b45c1561010fe8eda162ade1adphoglund@webrtc.org
3769e3fb96715bd0b45c1561010fe8eda162ade1adphoglund@webrtc.org protected:
3869e3fb96715bd0b45c1561010fe8eda162ade1adphoglund@webrtc.org  virtual void Run();
3969e3fb96715bd0b45c1561010fe8eda162ade1adphoglund@webrtc.org
4069e3fb96715bd0b45c1561010fe8eda162ade1adphoglund@webrtc.org private:
4169e3fb96715bd0b45c1561010fe8eda162ade1adphoglund@webrtc.org  ThreadRunFunction    run_function_;
4269e3fb96715bd0b45c1561010fe8eda162ade1adphoglund@webrtc.org  ThreadObj            obj_;
4369e3fb96715bd0b45c1561010fe8eda162ade1adphoglund@webrtc.org
4469e3fb96715bd0b45c1561010fe8eda162ade1adphoglund@webrtc.org  bool                    alive_;
4569e3fb96715bd0b45c1561010fe8eda162ade1adphoglund@webrtc.org  bool                    dead_;
4669e3fb96715bd0b45c1561010fe8eda162ade1adphoglund@webrtc.org
4769e3fb96715bd0b45c1561010fe8eda162ade1adphoglund@webrtc.org  // TODO(hellner)
4869e3fb96715bd0b45c1561010fe8eda162ade1adphoglund@webrtc.org  // do_not_close_handle_ member seem pretty redundant. Should be able to remove
4969e3fb96715bd0b45c1561010fe8eda162ade1adphoglund@webrtc.org  // it. Basically it should be fine to reclaim the handle when calling stop
5069e3fb96715bd0b45c1561010fe8eda162ade1adphoglund@webrtc.org  // and in the destructor.
5169e3fb96715bd0b45c1561010fe8eda162ade1adphoglund@webrtc.org  bool                    do_not_close_handle_;
5269e3fb96715bd0b45c1561010fe8eda162ade1adphoglund@webrtc.org  ThreadPriority          prio_;
5369e3fb96715bd0b45c1561010fe8eda162ade1adphoglund@webrtc.org  EventWrapper*           event_;
5469e3fb96715bd0b45c1561010fe8eda162ade1adphoglund@webrtc.org  CriticalSectionWrapper* critsect_stop_;
5569e3fb96715bd0b45c1561010fe8eda162ade1adphoglund@webrtc.org
5669e3fb96715bd0b45c1561010fe8eda162ade1adphoglund@webrtc.org  HANDLE                  thread_;
5769e3fb96715bd0b45c1561010fe8eda162ade1adphoglund@webrtc.org  unsigned int            id_;
5869e3fb96715bd0b45c1561010fe8eda162ade1adphoglund@webrtc.org  char                    name_[kThreadMaxNameLength];
5969e3fb96715bd0b45c1561010fe8eda162ade1adphoglund@webrtc.org  bool                    set_thread_name_;
60b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org
61b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org};
6269e3fb96715bd0b45c1561010fe8eda162ade1adphoglund@webrtc.org
633b89e10f31160da35b408fd00cb8f89d2b08862dpbos@webrtc.org}  // namespace webrtc
64b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org
6569e3fb96715bd0b45c1561010fe8eda162ade1adphoglund@webrtc.org#endif  // WEBRTC_SYSTEM_WRAPPERS_SOURCE_THREAD_WIN_H_
66