niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
henrike@webrtc.org | 143abd9 | 2012-02-08 19:39:38 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3 | * |
| 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.com | b5c49ff | 2011-08-01 17:04:04 +0000 | [diff] [blame] | 11 | #ifndef WEBRTC_SYSTEM_WRAPPERS_SOURCE_THREAD_POSIX_H_ |
| 12 | #define WEBRTC_SYSTEM_WRAPPERS_SOURCE_THREAD_POSIX_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | |
tommi@webrtc.org | d0165c6 | 2015-02-09 11:47:57 +0000 | [diff] [blame] | 14 | #include "webrtc/base/event.h" |
tommi@webrtc.org | d43bdf5 | 2015-02-03 16:29:57 +0000 | [diff] [blame] | 15 | #include "webrtc/base/scoped_ptr.h" |
| 16 | #include "webrtc/base/thread_checker.h" |
phoglund@webrtc.org | ec9c942 | 2013-01-02 08:45:03 +0000 | [diff] [blame] | 17 | #include "webrtc/system_wrappers/interface/thread_wrapper.h" |
| 18 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 19 | #include <pthread.h> |
| 20 | |
| 21 | namespace webrtc { |
hta@webrtc.org | 4030013 | 2012-05-23 15:49:48 +0000 | [diff] [blame] | 22 | |
phoglund@webrtc.org | ec9c942 | 2013-01-02 08:45:03 +0000 | [diff] [blame] | 23 | int ConvertToSystemPriority(ThreadPriority priority, int min_prio, |
| 24 | int max_prio); |
henrike@webrtc.org | 5ba4411 | 2012-10-05 14:36:54 +0000 | [diff] [blame] | 25 | |
phoglund@webrtc.org | ec9c942 | 2013-01-02 08:45:03 +0000 | [diff] [blame] | 26 | class ThreadPosix : public ThreadWrapper { |
| 27 | public: |
phoglund@webrtc.org | ec9c942 | 2013-01-02 08:45:03 +0000 | [diff] [blame] | 28 | ThreadPosix(ThreadRunFunction func, ThreadObj obj, ThreadPriority prio, |
| 29 | const char* thread_name); |
tommi@webrtc.org | d43bdf5 | 2015-02-03 16:29:57 +0000 | [diff] [blame] | 30 | ~ThreadPosix() override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 31 | |
phoglund@webrtc.org | ec9c942 | 2013-01-02 08:45:03 +0000 | [diff] [blame] | 32 | // From ThreadWrapper. |
pbos@webrtc.org | 8663973 | 2015-03-13 00:06:21 +0000 | [diff] [blame] | 33 | bool Start() override; |
tommi@webrtc.org | d43bdf5 | 2015-02-03 16:29:57 +0000 | [diff] [blame] | 34 | bool Stop() override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 35 | |
phoglund@webrtc.org | ec9c942 | 2013-01-02 08:45:03 +0000 | [diff] [blame] | 36 | private: |
tommi@webrtc.org | d43bdf5 | 2015-02-03 16:29:57 +0000 | [diff] [blame] | 37 | static void* StartThread(void* param); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 38 | |
pbos@webrtc.org | 8663973 | 2015-03-13 00:06:21 +0000 | [diff] [blame] | 39 | void Run(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 40 | |
tommi@webrtc.org | d43bdf5 | 2015-02-03 16:29:57 +0000 | [diff] [blame] | 41 | rtc::ThreadChecker thread_checker_; |
| 42 | ThreadRunFunction const run_function_; |
| 43 | void* const obj_; |
| 44 | ThreadPriority prio_; |
tommi@webrtc.org | d0165c6 | 2015-02-09 11:47:57 +0000 | [diff] [blame] | 45 | rtc::Event stop_event_; |
tommi@webrtc.org | d43bdf5 | 2015-02-03 16:29:57 +0000 | [diff] [blame] | 46 | const std::string name_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 47 | |
tommi@webrtc.org | d43bdf5 | 2015-02-03 16:29:57 +0000 | [diff] [blame] | 48 | pthread_t thread_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 49 | }; |
phoglund@webrtc.org | ec9c942 | 2013-01-02 08:45:03 +0000 | [diff] [blame] | 50 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 51 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 52 | |
phoglund@webrtc.org | ec9c942 | 2013-01-02 08:45:03 +0000 | [diff] [blame] | 53 | #endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_THREAD_POSIX_H_ |