| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 }; | 52 }; |
| 53 | 53 |
| 54 // Represents a simple worker thread. The implementation must be assumed | 54 // Represents a simple worker thread. The implementation must be assumed |
| 55 // to be single threaded, meaning that all methods of the class, must be | 55 // to be single threaded, meaning that all methods of the class, must be |
| 56 // called from the same thread, including instantiation. | 56 // called from the same thread, including instantiation. |
| 57 class PlatformThread { | 57 class PlatformThread { |
| 58 public: | 58 public: |
| 59 PlatformThread(ThreadRunFunction func, void* obj, const char* thread_name); | 59 PlatformThread(ThreadRunFunction func, void* obj, const char* thread_name); |
| 60 virtual ~PlatformThread(); | 60 virtual ~PlatformThread(); |
| 61 | 61 |
| 62 const std::string& name() const { return name_; } |
| 63 |
| 62 // Spawns a thread and tries to set thread priority according to the priority | 64 // Spawns a thread and tries to set thread priority according to the priority |
| 63 // from when CreateThread was called. | 65 // from when CreateThread was called. |
| 64 void Start(); | 66 void Start(); |
| 65 | 67 |
| 66 bool IsRunning() const; | 68 bool IsRunning() const; |
| 67 | 69 |
| 70 // Returns an identifier for the worker thread that can be used to do |
| 71 // thread checks. |
| 72 PlatformThreadRef GetThreadRef() const; |
| 73 |
| 68 // Stops (joins) the spawned thread. | 74 // Stops (joins) the spawned thread. |
| 69 void Stop(); | 75 void Stop(); |
| 70 | 76 |
| 71 // Set the priority of the thread. Must be called when thread is running. | 77 // Set the priority of the thread. Must be called when thread is running. |
| 72 bool SetPriority(ThreadPriority priority); | 78 bool SetPriority(ThreadPriority priority); |
| 73 | 79 |
| 80 protected: |
| 81 #if defined(WEBRTC_WIN) |
| 82 // Exposed to derived classes to allow for special cases specific to Windows. |
| 83 bool QueueAPC(PAPCFUNC apc_function, ULONG_PTR data); |
| 84 #endif |
| 85 |
| 74 private: | 86 private: |
| 75 void Run(); | 87 void Run(); |
| 76 | 88 |
| 77 ThreadRunFunction const run_function_; | 89 ThreadRunFunction const run_function_; |
| 78 void* const obj_; | 90 void* const obj_; |
| 79 // TODO(pbos): Make sure call sites use string literals and update to a const | 91 // TODO(pbos): Make sure call sites use string literals and update to a const |
| 80 // char* instead of a std::string. | 92 // char* instead of a std::string. |
| 81 const std::string name_; | 93 const std::string name_; |
| 82 rtc::ThreadChecker thread_checker_; | 94 rtc::ThreadChecker thread_checker_; |
| 83 #if defined(WEBRTC_WIN) | 95 #if defined(WEBRTC_WIN) |
| 84 static DWORD WINAPI StartThread(void* param); | 96 static DWORD WINAPI StartThread(void* param); |
| 85 | 97 |
| 86 bool stop_; | 98 bool stop_; |
| 87 HANDLE thread_; | 99 HANDLE thread_; |
| 100 DWORD thread_id_; |
| 88 #else | 101 #else |
| 89 static void* StartThread(void* param); | 102 static void* StartThread(void* param); |
| 90 | 103 |
| 91 rtc::Event stop_event_; | 104 rtc::Event stop_event_; |
| 92 | 105 |
| 93 pthread_t thread_; | 106 pthread_t thread_; |
| 94 #endif // defined(WEBRTC_WIN) | 107 #endif // defined(WEBRTC_WIN) |
| 95 RTC_DISALLOW_COPY_AND_ASSIGN(PlatformThread); | 108 RTC_DISALLOW_COPY_AND_ASSIGN(PlatformThread); |
| 96 }; | 109 }; |
| 97 | 110 |
| 98 } // namespace rtc | 111 } // namespace rtc |
| 99 | 112 |
| 100 #endif // WEBRTC_BASE_PLATFORM_THREAD_H_ | 113 #endif // WEBRTC_BASE_PLATFORM_THREAD_H_ |
| OLD | NEW |