blob: ec9c10e983426743ac4b35376f5cfa131556ccd2 [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:
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000028 ThreadPosix(ThreadRunFunction func, ThreadObj obj, ThreadPriority prio,
29 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.
tommi@webrtc.orgd43bdf52015-02-03 16:29:57 +000033 bool Start(unsigned int& id) override;
34 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
tommi@webrtc.orgd43bdf52015-02-03 16:29:57 +000039 struct InitParams;
40 void Run(InitParams* params);
niklase@google.com470e71d2011-07-07 08:21:25 +000041
tommi@webrtc.orgd43bdf52015-02-03 16:29:57 +000042 rtc::ThreadChecker thread_checker_;
43 ThreadRunFunction const run_function_;
44 void* const obj_;
45 ThreadPriority prio_;
tommi@webrtc.orgd0165c62015-02-09 11:47:57 +000046 rtc::Event stop_event_;
tommi@webrtc.orgd43bdf52015-02-03 16:29:57 +000047 const std::string name_;
niklase@google.com470e71d2011-07-07 08:21:25 +000048
tommi@webrtc.orgd43bdf52015-02-03 16:29:57 +000049 pid_t thread_id_;
50 pthread_t thread_;
niklase@google.com470e71d2011-07-07 08:21:25 +000051};
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000052
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +000053} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +000054
phoglund@webrtc.orgec9c9422013-01-02 08:45:03 +000055#endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_THREAD_POSIX_H_