blob: cd42c33e2f9cae8a130c6b32ae7bbd35025bf7d9 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
henrike@webrtc.org143abd92012-02-08 19:39:38 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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
ajm@google.comb5c49ff2011-08-01 17:04:04 +000011#ifndef WEBRTC_SYSTEM_WRAPPERS_SOURCE_THREAD_POSIX_H_
12#define WEBRTC_SYSTEM_WRAPPERS_SOURCE_THREAD_POSIX_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
tommi@webrtc.orgd43bdf52015-02-03 16:29:57 +000014#include "webrtc/base/scoped_ptr.h"
15#include "webrtc/base/thread_checker.h"
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000016#include "webrtc/system_wrappers/interface/thread_wrapper.h"
17
niklase@google.com470e71d2011-07-07 08:21:25 +000018#include <pthread.h>
19
20namespace webrtc {
hta@webrtc.org40300132012-05-23 15:49:48 +000021
22class CriticalSectionWrapper;
niklase@google.com470e71d2011-07-07 08:21:25 +000023class EventWrapper;
24
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000025int ConvertToSystemPriority(ThreadPriority priority, int min_prio,
26 int max_prio);
henrike@webrtc.org5ba44112012-10-05 14:36:54 +000027
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000028class ThreadPosix : public ThreadWrapper {
29 public:
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000030 ThreadPosix(ThreadRunFunction func, ThreadObj obj, ThreadPriority prio,
31 const char* thread_name);
tommi@webrtc.orgd43bdf52015-02-03 16:29:57 +000032 ~ThreadPosix() override;
niklase@google.com470e71d2011-07-07 08:21:25 +000033
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000034 // From ThreadWrapper.
tommi@webrtc.orgd43bdf52015-02-03 16:29:57 +000035 void SetNotAlive() override;
36 bool Start(unsigned int& id) override;
37 bool Stop() override;
niklase@google.com470e71d2011-07-07 08:21:25 +000038
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000039 private:
tommi@webrtc.orgd43bdf52015-02-03 16:29:57 +000040 static void* StartThread(void* param);
niklase@google.com470e71d2011-07-07 08:21:25 +000041
tommi@webrtc.orgd43bdf52015-02-03 16:29:57 +000042 struct InitParams;
43 void Run(InitParams* params);
niklase@google.com470e71d2011-07-07 08:21:25 +000044
tommi@webrtc.orgd43bdf52015-02-03 16:29:57 +000045 rtc::ThreadChecker thread_checker_;
46 ThreadRunFunction const run_function_;
47 void* const obj_;
48 ThreadPriority prio_;
49 // TODO(tommi): std::condition_variable?
50 const rtc::scoped_ptr<EventWrapper> stop_event_;
51 const std::string name_;
niklase@google.com470e71d2011-07-07 08:21:25 +000052
tommi@webrtc.orgd43bdf52015-02-03 16:29:57 +000053 pid_t thread_id_;
54 pthread_t thread_;
niklase@google.com470e71d2011-07-07 08:21:25 +000055};
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000056
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +000057} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +000058
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000059#endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_THREAD_POSIX_H_