blob: ccc52b642aba0c29c05b74a4d53107fe6ccce7ba [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.orgd0165c62015-02-09 11:47:57 +000014#include "webrtc/base/event.h"
tommi@webrtc.orgd43bdf52015-02-03 16:29:57 +000015#include "webrtc/base/scoped_ptr.h"
16#include "webrtc/base/thread_checker.h"
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000017#include "webrtc/system_wrappers/interface/thread_wrapper.h"
18
niklase@google.com470e71d2011-07-07 08:21:25 +000019#include <pthread.h>
20
21namespace webrtc {
hta@webrtc.org40300132012-05-23 15:49:48 +000022
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000023int ConvertToSystemPriority(ThreadPriority priority, int min_prio,
24 int max_prio);
henrike@webrtc.org5ba44112012-10-05 14:36:54 +000025
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000026class ThreadPosix : public ThreadWrapper {
27 public:
tommi@webrtc.org27c0be92015-03-19 14:35:58 +000028 ThreadPosix(ThreadRunFunction func, void* obj, ThreadPriority prio,
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000029 const char* thread_name);
tommi@webrtc.orgd43bdf52015-02-03 16:29:57 +000030 ~ThreadPosix() override;
niklase@google.com470e71d2011-07-07 08:21:25 +000031
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000032 // From ThreadWrapper.
pbos@webrtc.org86639732015-03-13 00:06:21 +000033 bool Start() override;
tommi@webrtc.orgd43bdf52015-02-03 16:29:57 +000034 bool Stop() override;
niklase@google.com470e71d2011-07-07 08:21:25 +000035
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000036 private:
tommi@webrtc.orgd43bdf52015-02-03 16:29:57 +000037 static void* StartThread(void* param);
niklase@google.com470e71d2011-07-07 08:21:25 +000038
pbos@webrtc.org86639732015-03-13 00:06:21 +000039 void Run();
niklase@google.com470e71d2011-07-07 08:21:25 +000040
tommi@webrtc.orgd43bdf52015-02-03 16:29:57 +000041 rtc::ThreadChecker thread_checker_;
42 ThreadRunFunction const run_function_;
43 void* const obj_;
44 ThreadPriority prio_;
tommi@webrtc.orgd0165c62015-02-09 11:47:57 +000045 rtc::Event stop_event_;
tommi@webrtc.orgd43bdf52015-02-03 16:29:57 +000046 const std::string name_;
niklase@google.com470e71d2011-07-07 08:21:25 +000047
tommi@webrtc.orgd43bdf52015-02-03 16:29:57 +000048 pthread_t thread_;
niklase@google.com470e71d2011-07-07 08:21:25 +000049};
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000050
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +000051} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +000052
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000053#endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_THREAD_POSIX_H_