blob: 88c55af02812c4e91dd23ab9486d78ed7130b3ac [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 bool Start(unsigned int& id) override;
36 bool Stop() override;
niklase@google.com470e71d2011-07-07 08:21:25 +000037
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000038 private:
tommi@webrtc.orgd43bdf52015-02-03 16:29:57 +000039 static void* StartThread(void* param);
niklase@google.com470e71d2011-07-07 08:21:25 +000040
tommi@webrtc.orgd43bdf52015-02-03 16:29:57 +000041 struct InitParams;
42 void Run(InitParams* params);
niklase@google.com470e71d2011-07-07 08:21:25 +000043
tommi@webrtc.orgd43bdf52015-02-03 16:29:57 +000044 rtc::ThreadChecker thread_checker_;
45 ThreadRunFunction const run_function_;
46 void* const obj_;
47 ThreadPriority prio_;
48 // TODO(tommi): std::condition_variable?
49 const rtc::scoped_ptr<EventWrapper> stop_event_;
50 const std::string name_;
niklase@google.com470e71d2011-07-07 08:21:25 +000051
tommi@webrtc.orgd43bdf52015-02-03 16:29:57 +000052 pid_t thread_id_;
53 pthread_t thread_;
niklase@google.com470e71d2011-07-07 08:21:25 +000054};
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000055
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +000056} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +000057
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000058#endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_THREAD_POSIX_H_