henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
| 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef RTC_BASE_THREAD_H_ |
| 12 | #define RTC_BASE_THREAD_H_ |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 13 | |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 14 | #include <stdint.h> |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 15 | |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 16 | #include <list> |
Sebastian Jansson | da7267a | 2020-03-03 10:48:05 +0100 | [diff] [blame] | 17 | #include <map> |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 18 | #include <memory> |
Sebastian Jansson | 6ea2c6a | 2020-01-13 14:07:22 +0100 | [diff] [blame] | 19 | #include <queue> |
Sebastian Jansson | da7267a | 2020-03-03 10:48:05 +0100 | [diff] [blame] | 20 | #include <set> |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 21 | #include <string> |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 22 | #include <type_traits> |
Sebastian Jansson | 6ea2c6a | 2020-01-13 14:07:22 +0100 | [diff] [blame] | 23 | #include <vector> |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 24 | |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 25 | #if defined(WEBRTC_POSIX) |
| 26 | #include <pthread.h> |
| 27 | #endif |
Danil Chapovalov | 8931345 | 2019-11-29 12:56:43 +0100 | [diff] [blame] | 28 | #include "api/function_view.h" |
Danil Chapovalov | 912b3b8 | 2019-11-22 15:52:40 +0100 | [diff] [blame] | 29 | #include "api/task_queue/queued_task.h" |
| 30 | #include "api/task_queue/task_queue_base.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 31 | #include "rtc_base/constructor_magic.h" |
Markus Handell | 3cb525b | 2020-07-16 16:16:09 +0200 | [diff] [blame] | 32 | #include "rtc_base/deprecated/recursive_critical_section.h" |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 33 | #include "rtc_base/location.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 34 | #include "rtc_base/message_handler.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 35 | #include "rtc_base/platform_thread_types.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 36 | #include "rtc_base/socket_server.h" |
Mirko Bonadei | 35214fc | 2019-09-23 14:54:28 +0200 | [diff] [blame] | 37 | #include "rtc_base/system/rtc_export.h" |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 38 | #include "rtc_base/thread_annotations.h" |
Sebastian Jansson | 6ea2c6a | 2020-01-13 14:07:22 +0100 | [diff] [blame] | 39 | #include "rtc_base/thread_message.h" |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 40 | |
| 41 | #if defined(WEBRTC_WIN) |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 42 | #include "rtc_base/win32.h" |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 43 | #endif |
| 44 | |
| 45 | namespace rtc { |
| 46 | |
| 47 | class Thread; |
| 48 | |
Henrik Boström | ba4dcc3 | 2019-02-28 09:34:06 +0100 | [diff] [blame] | 49 | namespace rtc_thread_internal { |
| 50 | |
Niels Möller | f13a096 | 2019-05-17 10:15:06 +0200 | [diff] [blame] | 51 | class MessageLikeTask : public MessageData { |
Henrik Boström | ba4dcc3 | 2019-02-28 09:34:06 +0100 | [diff] [blame] | 52 | public: |
Niels Möller | f13a096 | 2019-05-17 10:15:06 +0200 | [diff] [blame] | 53 | virtual void Run() = 0; |
| 54 | }; |
| 55 | |
| 56 | template <class FunctorT> |
| 57 | class MessageWithFunctor final : public MessageLikeTask { |
| 58 | public: |
| 59 | explicit MessageWithFunctor(FunctorT&& functor) |
Henrik Boström | ba4dcc3 | 2019-02-28 09:34:06 +0100 | [diff] [blame] | 60 | : functor_(std::forward<FunctorT>(functor)) {} |
| 61 | |
Niels Möller | f13a096 | 2019-05-17 10:15:06 +0200 | [diff] [blame] | 62 | void Run() override { functor_(); } |
Henrik Boström | ba4dcc3 | 2019-02-28 09:34:06 +0100 | [diff] [blame] | 63 | |
| 64 | private: |
Niels Möller | f13a096 | 2019-05-17 10:15:06 +0200 | [diff] [blame] | 65 | ~MessageWithFunctor() override {} |
Henrik Boström | ba4dcc3 | 2019-02-28 09:34:06 +0100 | [diff] [blame] | 66 | |
| 67 | typename std::remove_reference<FunctorT>::type functor_; |
| 68 | |
Niels Möller | f13a096 | 2019-05-17 10:15:06 +0200 | [diff] [blame] | 69 | RTC_DISALLOW_COPY_AND_ASSIGN(MessageWithFunctor); |
| 70 | }; |
| 71 | |
Henrik Boström | ba4dcc3 | 2019-02-28 09:34:06 +0100 | [diff] [blame] | 72 | } // namespace rtc_thread_internal |
| 73 | |
Mirko Bonadei | 35214fc | 2019-09-23 14:54:28 +0200 | [diff] [blame] | 74 | class RTC_EXPORT ThreadManager { |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 75 | public: |
| 76 | static const int kForever = -1; |
| 77 | |
| 78 | // Singleton, constructor and destructor are private. |
| 79 | static ThreadManager* Instance(); |
| 80 | |
Sebastian Jansson | 6ea2c6a | 2020-01-13 14:07:22 +0100 | [diff] [blame] | 81 | static void Add(Thread* message_queue); |
| 82 | static void Remove(Thread* message_queue); |
| 83 | static void Clear(MessageHandler* handler); |
| 84 | |
Sebastian Jansson | 6ea2c6a | 2020-01-13 14:07:22 +0100 | [diff] [blame] | 85 | // For testing purposes, for use with a simulated clock. |
| 86 | // Ensures that all message queues have processed delayed messages |
| 87 | // up until the current point in time. |
| 88 | static void ProcessAllMessageQueuesForTesting(); |
| 89 | |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 90 | Thread* CurrentThread(); |
| 91 | void SetCurrentThread(Thread* thread); |
Sebastian Jansson | 178a685 | 2020-01-14 11:12:26 +0100 | [diff] [blame] | 92 | // Allows changing the current thread, this is intended for tests where we |
| 93 | // want to simulate multiple threads running on a single physical thread. |
| 94 | void ChangeCurrentThreadForTest(Thread* thread); |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 95 | |
| 96 | // Returns a thread object with its thread_ ivar set |
| 97 | // to whatever the OS uses to represent the thread. |
| 98 | // If there already *is* a Thread object corresponding to this thread, |
| 99 | // this method will return that. Otherwise it creates a new Thread |
| 100 | // object whose wrapped() method will return true, and whose |
| 101 | // handle will, on Win32, be opened with only synchronization privileges - |
| 102 | // if you need more privilegs, rather than changing this method, please |
| 103 | // write additional code to adjust the privileges, or call a different |
| 104 | // factory method of your own devising, because this one gets used in |
| 105 | // unexpected contexts (like inside browser plugins) and it would be a |
| 106 | // shame to break it. It is also conceivable on Win32 that we won't even |
| 107 | // be able to get synchronization privileges, in which case the result |
| 108 | // will have a null handle. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 109 | Thread* WrapCurrentThread(); |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 110 | void UnwrapCurrentThread(); |
| 111 | |
Niels Moller | 9d1840c | 2019-05-21 07:26:37 +0000 | [diff] [blame] | 112 | bool IsMainThread(); |
| 113 | |
Sebastian Jansson | da7267a | 2020-03-03 10:48:05 +0100 | [diff] [blame] | 114 | #if RTC_DCHECK_IS_ON |
| 115 | // Registers that a Send operation is to be performed between |source| and |
| 116 | // |target|, while checking that this does not cause a send cycle that could |
| 117 | // potentially cause a deadlock. |
| 118 | void RegisterSendAndCheckForCycles(Thread* source, Thread* target); |
| 119 | #endif |
| 120 | |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 121 | private: |
| 122 | ThreadManager(); |
| 123 | ~ThreadManager(); |
| 124 | |
Sebastian Jansson | 178a685 | 2020-01-14 11:12:26 +0100 | [diff] [blame] | 125 | void SetCurrentThreadInternal(Thread* thread); |
Sebastian Jansson | 6ea2c6a | 2020-01-13 14:07:22 +0100 | [diff] [blame] | 126 | void AddInternal(Thread* message_queue); |
| 127 | void RemoveInternal(Thread* message_queue); |
| 128 | void ClearInternal(MessageHandler* handler); |
| 129 | void ProcessAllMessageQueuesInternal(); |
Sebastian Jansson | da7267a | 2020-03-03 10:48:05 +0100 | [diff] [blame] | 130 | #if RTC_DCHECK_IS_ON |
| 131 | void RemoveFromSendGraph(Thread* thread) RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_); |
| 132 | #endif |
Sebastian Jansson | 6ea2c6a | 2020-01-13 14:07:22 +0100 | [diff] [blame] | 133 | |
| 134 | // This list contains all live Threads. |
| 135 | std::vector<Thread*> message_queues_ RTC_GUARDED_BY(crit_); |
| 136 | |
| 137 | // Methods that don't modify the list of message queues may be called in a |
| 138 | // re-entrant fashion. "processing_" keeps track of the depth of re-entrant |
| 139 | // calls. |
Markus Handell | 3cb525b | 2020-07-16 16:16:09 +0200 | [diff] [blame] | 140 | RecursiveCriticalSection crit_; |
Sebastian Jansson | 6ea2c6a | 2020-01-13 14:07:22 +0100 | [diff] [blame] | 141 | size_t processing_ RTC_GUARDED_BY(crit_) = 0; |
Sebastian Jansson | da7267a | 2020-03-03 10:48:05 +0100 | [diff] [blame] | 142 | #if RTC_DCHECK_IS_ON |
| 143 | // Represents all thread seand actions by storing all send targets per thread. |
| 144 | // This is used by RegisterSendAndCheckForCycles. This graph has no cycles |
| 145 | // since we will trigger a CHECK failure if a cycle is introduced. |
| 146 | std::map<Thread*, std::set<Thread*>> send_graph_ RTC_GUARDED_BY(crit_); |
| 147 | #endif |
Sebastian Jansson | 6ea2c6a | 2020-01-13 14:07:22 +0100 | [diff] [blame] | 148 | |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 149 | #if defined(WEBRTC_POSIX) |
| 150 | pthread_key_t key_; |
| 151 | #endif |
| 152 | |
| 153 | #if defined(WEBRTC_WIN) |
Tommi | 5149242 | 2017-12-04 15:18:23 +0100 | [diff] [blame] | 154 | const DWORD key_; |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 155 | #endif |
| 156 | |
Niels Moller | 9d1840c | 2019-05-21 07:26:37 +0000 | [diff] [blame] | 157 | // The thread to potentially autowrap. |
| 158 | const PlatformThreadRef main_thread_ref_; |
| 159 | |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 160 | RTC_DISALLOW_COPY_AND_ASSIGN(ThreadManager); |
| 161 | }; |
| 162 | |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 163 | // WARNING! SUBCLASSES MUST CALL Stop() IN THEIR DESTRUCTORS! See ~Thread(). |
| 164 | |
Sebastian Jansson | 6ea2c6a | 2020-01-13 14:07:22 +0100 | [diff] [blame] | 165 | class RTC_LOCKABLE RTC_EXPORT Thread : public webrtc::TaskQueueBase { |
tommi | a8a3515 | 2017-07-13 05:47:25 -0700 | [diff] [blame] | 166 | public: |
Sebastian Jansson | 6ea2c6a | 2020-01-13 14:07:22 +0100 | [diff] [blame] | 167 | static const int kForever = -1; |
| 168 | |
| 169 | // Create a new Thread and optionally assign it to the passed |
| 170 | // SocketServer. Subclasses that override Clear should pass false for |
| 171 | // init_queue and call DoInit() from their constructor to prevent races |
| 172 | // with the ThreadManager using the object while the vtable is still |
| 173 | // being created. |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 174 | explicit Thread(SocketServer* ss); |
| 175 | explicit Thread(std::unique_ptr<SocketServer> ss); |
Sebastian Jansson | 6ea2c6a | 2020-01-13 14:07:22 +0100 | [diff] [blame] | 176 | |
Taylor Brandstetter | 0867260 | 2018-03-02 15:20:33 -0800 | [diff] [blame] | 177 | // Constructors meant for subclasses; they should call DoInit themselves and |
| 178 | // pass false for |do_init|, so that DoInit is called only on the fully |
| 179 | // instantiated class, which avoids a vptr data race. |
| 180 | Thread(SocketServer* ss, bool do_init); |
| 181 | Thread(std::unique_ptr<SocketServer> ss, bool do_init); |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 182 | |
| 183 | // NOTE: ALL SUBCLASSES OF Thread MUST CALL Stop() IN THEIR DESTRUCTORS (or |
| 184 | // guarantee Stop() is explicitly called before the subclass is destroyed). |
| 185 | // This is required to avoid a data race between the destructor modifying the |
| 186 | // vtable, and the Thread::PreRun calling the virtual method Run(). |
Sebastian Jansson | 6ea2c6a | 2020-01-13 14:07:22 +0100 | [diff] [blame] | 187 | |
| 188 | // NOTE: SUBCLASSES OF Thread THAT OVERRIDE Clear MUST CALL |
| 189 | // DoDestroy() IN THEIR DESTRUCTORS! This is required to avoid a data race |
| 190 | // between the destructor modifying the vtable, and the ThreadManager |
| 191 | // calling Clear on the object from a different thread. |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 192 | ~Thread() override; |
| 193 | |
| 194 | static std::unique_ptr<Thread> CreateWithSocketServer(); |
| 195 | static std::unique_ptr<Thread> Create(); |
| 196 | static Thread* Current(); |
| 197 | |
| 198 | // Used to catch performance regressions. Use this to disallow blocking calls |
| 199 | // (Invoke) for a given scope. If a synchronous call is made while this is in |
| 200 | // effect, an assert will be triggered. |
| 201 | // Note that this is a single threaded class. |
| 202 | class ScopedDisallowBlockingCalls { |
| 203 | public: |
| 204 | ScopedDisallowBlockingCalls(); |
Sebastian Jansson | 9debe5a | 2019-03-22 15:42:38 +0100 | [diff] [blame] | 205 | ScopedDisallowBlockingCalls(const ScopedDisallowBlockingCalls&) = delete; |
| 206 | ScopedDisallowBlockingCalls& operator=(const ScopedDisallowBlockingCalls&) = |
| 207 | delete; |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 208 | ~ScopedDisallowBlockingCalls(); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 209 | |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 210 | private: |
| 211 | Thread* const thread_; |
| 212 | const bool previous_state_; |
| 213 | }; |
| 214 | |
Sebastian Jansson | 6ea2c6a | 2020-01-13 14:07:22 +0100 | [diff] [blame] | 215 | SocketServer* socketserver(); |
| 216 | |
| 217 | // Note: The behavior of Thread has changed. When a thread is stopped, |
| 218 | // futher Posts and Sends will fail. However, any pending Sends and *ready* |
| 219 | // Posts (as opposed to unexpired delayed Posts) will be delivered before |
| 220 | // Get (or Peek) returns false. By guaranteeing delivery of those messages, |
| 221 | // we eliminate the race condition when an MessageHandler and Thread |
| 222 | // may be destroyed independently of each other. |
| 223 | virtual void Quit(); |
| 224 | virtual bool IsQuitting(); |
| 225 | virtual void Restart(); |
| 226 | // Not all message queues actually process messages (such as SignalThread). |
| 227 | // In those cases, it's important to know, before posting, that it won't be |
| 228 | // Processed. Normally, this would be true until IsQuitting() is true. |
| 229 | virtual bool IsProcessingMessagesForTesting(); |
| 230 | |
| 231 | // Get() will process I/O until: |
| 232 | // 1) A message is available (returns true) |
| 233 | // 2) cmsWait seconds have elapsed (returns false) |
| 234 | // 3) Stop() is called (returns false) |
| 235 | virtual bool Get(Message* pmsg, |
| 236 | int cmsWait = kForever, |
| 237 | bool process_io = true); |
| 238 | virtual bool Peek(Message* pmsg, int cmsWait = 0); |
Sebastian Jansson | 61380c0 | 2020-01-17 14:46:08 +0100 | [diff] [blame] | 239 | // |time_sensitive| is deprecated and should always be false. |
Sebastian Jansson | 6ea2c6a | 2020-01-13 14:07:22 +0100 | [diff] [blame] | 240 | virtual void Post(const Location& posted_from, |
| 241 | MessageHandler* phandler, |
| 242 | uint32_t id = 0, |
| 243 | MessageData* pdata = nullptr, |
| 244 | bool time_sensitive = false); |
| 245 | virtual void PostDelayed(const Location& posted_from, |
Sebastian Jansson | 61380c0 | 2020-01-17 14:46:08 +0100 | [diff] [blame] | 246 | int delay_ms, |
Sebastian Jansson | 6ea2c6a | 2020-01-13 14:07:22 +0100 | [diff] [blame] | 247 | MessageHandler* phandler, |
| 248 | uint32_t id = 0, |
| 249 | MessageData* pdata = nullptr); |
| 250 | virtual void PostAt(const Location& posted_from, |
Sebastian Jansson | 61380c0 | 2020-01-17 14:46:08 +0100 | [diff] [blame] | 251 | int64_t run_at_ms, |
Sebastian Jansson | 6ea2c6a | 2020-01-13 14:07:22 +0100 | [diff] [blame] | 252 | MessageHandler* phandler, |
| 253 | uint32_t id = 0, |
| 254 | MessageData* pdata = nullptr); |
| 255 | virtual void Clear(MessageHandler* phandler, |
| 256 | uint32_t id = MQID_ANY, |
| 257 | MessageList* removed = nullptr); |
| 258 | virtual void Dispatch(Message* pmsg); |
Sebastian Jansson | 6ea2c6a | 2020-01-13 14:07:22 +0100 | [diff] [blame] | 259 | |
| 260 | // Amount of time until the next message can be retrieved |
| 261 | virtual int GetDelay(); |
| 262 | |
| 263 | bool empty() const { return size() == 0u; } |
| 264 | size_t size() const { |
Sebastian Jansson | 61380c0 | 2020-01-17 14:46:08 +0100 | [diff] [blame] | 265 | CritScope cs(&crit_); |
| 266 | return messages_.size() + delayed_messages_.size() + (fPeekKeep_ ? 1u : 0u); |
Sebastian Jansson | 6ea2c6a | 2020-01-13 14:07:22 +0100 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | // Internally posts a message which causes the doomed object to be deleted |
| 270 | template <class T> |
| 271 | void Dispose(T* doomed) { |
| 272 | if (doomed) { |
| 273 | Post(RTC_FROM_HERE, nullptr, MQID_DISPOSE, new DisposeData<T>(doomed)); |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | // When this signal is sent out, any references to this queue should |
| 278 | // no longer be used. |
| 279 | sigslot::signal0<> SignalQueueDestroyed; |
| 280 | |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 281 | bool IsCurrent() const; |
| 282 | |
| 283 | // Sleeps the calling thread for the specified number of milliseconds, during |
| 284 | // which time no processing is performed. Returns false if sleeping was |
| 285 | // interrupted by a signal (POSIX only). |
| 286 | static bool SleepMs(int millis); |
| 287 | |
| 288 | // Sets the thread's name, for debugging. Must be called before Start(). |
| 289 | // If |obj| is non-null, its value is appended to |name|. |
| 290 | const std::string& name() const { return name_; } |
| 291 | bool SetName(const std::string& name, const void* obj); |
| 292 | |
| 293 | // Starts the execution of the thread. |
Niels Möller | d2e5013 | 2019-06-11 09:24:14 +0200 | [diff] [blame] | 294 | bool Start(); |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 295 | |
| 296 | // Tells the thread to stop and waits until it is joined. |
| 297 | // Never call Stop on the current thread. Instead use the inherited Quit |
Sebastian Jansson | 6ea2c6a | 2020-01-13 14:07:22 +0100 | [diff] [blame] | 298 | // function which will exit the base Thread without terminating the |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 299 | // underlying OS thread. |
| 300 | virtual void Stop(); |
| 301 | |
| 302 | // By default, Thread::Run() calls ProcessMessages(kForever). To do other |
| 303 | // work, override Run(). To receive and dispatch messages, call |
| 304 | // ProcessMessages occasionally. |
| 305 | virtual void Run(); |
| 306 | |
| 307 | virtual void Send(const Location& posted_from, |
| 308 | MessageHandler* phandler, |
| 309 | uint32_t id = 0, |
| 310 | MessageData* pdata = nullptr); |
| 311 | |
| 312 | // Convenience method to invoke a functor on another thread. Caller must |
| 313 | // provide the |ReturnT| template argument, which cannot (easily) be deduced. |
| 314 | // Uses Send() internally, which blocks the current thread until execution |
| 315 | // is complete. |
| 316 | // Ex: bool result = thread.Invoke<bool>(RTC_FROM_HERE, |
| 317 | // &MyFunctionReturningBool); |
| 318 | // NOTE: This function can only be called when synchronous calls are allowed. |
| 319 | // See ScopedDisallowBlockingCalls for details. |
Henrik Boström | ba4dcc3 | 2019-02-28 09:34:06 +0100 | [diff] [blame] | 320 | // NOTE: Blocking invokes are DISCOURAGED, consider if what you're doing can |
| 321 | // be achieved with PostTask() and callbacks instead. |
Danil Chapovalov | 8931345 | 2019-11-29 12:56:43 +0100 | [diff] [blame] | 322 | template < |
| 323 | class ReturnT, |
| 324 | typename = typename std::enable_if<!std::is_void<ReturnT>::value>::type> |
| 325 | ReturnT Invoke(const Location& posted_from, FunctionView<ReturnT()> functor) { |
| 326 | ReturnT result; |
| 327 | InvokeInternal(posted_from, [functor, &result] { result = functor(); }); |
| 328 | return result; |
| 329 | } |
| 330 | |
| 331 | template < |
| 332 | class ReturnT, |
| 333 | typename = typename std::enable_if<std::is_void<ReturnT>::value>::type> |
| 334 | void Invoke(const Location& posted_from, FunctionView<void()> functor) { |
| 335 | InvokeInternal(posted_from, functor); |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 336 | } |
| 337 | |
Artem Titov | dfc5f0d | 2020-07-03 12:09:26 +0200 | [diff] [blame] | 338 | // Allows invoke to specified |thread|. Thread never will be dereferenced and |
| 339 | // will be used only for reference-based comparison, so instance can be safely |
| 340 | // deleted. If NDEBUG is defined and DCHECK_ALWAYS_ON is undefined do nothing. |
| 341 | void AllowInvokesToThread(Thread* thread); |
Tomas Gunnarsson | abdb470 | 2020-09-05 18:43:36 +0200 | [diff] [blame] | 342 | |
Artem Titov | dfc5f0d | 2020-07-03 12:09:26 +0200 | [diff] [blame] | 343 | // If NDEBUG is defined and DCHECK_ALWAYS_ON is undefined do nothing. |
| 344 | void DisallowAllInvokes(); |
| 345 | // Returns true if |target| was allowed by AllowInvokesToThread() or if no |
| 346 | // calls were made to AllowInvokesToThread and DisallowAllInvokes. Otherwise |
| 347 | // returns false. |
| 348 | // If NDEBUG is defined and DCHECK_ALWAYS_ON is undefined always returns true. |
| 349 | bool IsInvokeToThreadAllowed(rtc::Thread* target); |
| 350 | |
Henrik Boström | ba4dcc3 | 2019-02-28 09:34:06 +0100 | [diff] [blame] | 351 | // Posts a task to invoke the functor on |this| thread asynchronously, i.e. |
| 352 | // without blocking the thread that invoked PostTask(). Ownership of |functor| |
Niels Möller | f13a096 | 2019-05-17 10:15:06 +0200 | [diff] [blame] | 353 | // is passed and (usually, see below) destroyed on |this| thread after it is |
| 354 | // invoked. |
Henrik Boström | ba4dcc3 | 2019-02-28 09:34:06 +0100 | [diff] [blame] | 355 | // Requirements of FunctorT: |
| 356 | // - FunctorT is movable. |
| 357 | // - FunctorT implements "T operator()()" or "T operator()() const" for some T |
| 358 | // (if T is not void, the return value is discarded on |this| thread). |
| 359 | // - FunctorT has a public destructor that can be invoked from |this| thread |
| 360 | // after operation() has been invoked. |
| 361 | // - The functor must not cause the thread to quit before PostTask() is done. |
| 362 | // |
Niels Möller | f13a096 | 2019-05-17 10:15:06 +0200 | [diff] [blame] | 363 | // Destruction of the functor/task mimics what TaskQueue::PostTask does: If |
| 364 | // the task is run, it will be destroyed on |this| thread. However, if there |
| 365 | // are pending tasks by the time the Thread is destroyed, or a task is posted |
| 366 | // to a thread that is quitting, the task is destroyed immediately, on the |
| 367 | // calling thread. Destroying the Thread only blocks for any currently running |
| 368 | // task to complete. Note that TQ abstraction is even vaguer on how |
| 369 | // destruction happens in these cases, allowing destruction to happen |
| 370 | // asynchronously at a later time and on some arbitrary thread. So to ease |
| 371 | // migration, don't depend on Thread::PostTask destroying un-run tasks |
| 372 | // immediately. |
| 373 | // |
Henrik Boström | ba4dcc3 | 2019-02-28 09:34:06 +0100 | [diff] [blame] | 374 | // Example - Calling a class method: |
| 375 | // class Foo { |
| 376 | // public: |
| 377 | // void DoTheThing(); |
| 378 | // }; |
| 379 | // Foo foo; |
| 380 | // thread->PostTask(RTC_FROM_HERE, Bind(&Foo::DoTheThing, &foo)); |
| 381 | // |
| 382 | // Example - Calling a lambda function: |
| 383 | // thread->PostTask(RTC_FROM_HERE, |
| 384 | // [&x, &y] { x.TrackComputations(y.Compute()); }); |
| 385 | template <class FunctorT> |
| 386 | void PostTask(const Location& posted_from, FunctorT&& functor) { |
Steve Anton | bcc1a76 | 2019-12-11 11:21:53 -0800 | [diff] [blame] | 387 | Post(posted_from, GetPostTaskMessageHandler(), /*id=*/0, |
Niels Möller | f13a096 | 2019-05-17 10:15:06 +0200 | [diff] [blame] | 388 | new rtc_thread_internal::MessageWithFunctor<FunctorT>( |
Henrik Boström | ba4dcc3 | 2019-02-28 09:34:06 +0100 | [diff] [blame] | 389 | std::forward<FunctorT>(functor))); |
Henrik Boström | ba4dcc3 | 2019-02-28 09:34:06 +0100 | [diff] [blame] | 390 | } |
Steve Anton | bcc1a76 | 2019-12-11 11:21:53 -0800 | [diff] [blame] | 391 | template <class FunctorT> |
| 392 | void PostDelayedTask(const Location& posted_from, |
| 393 | FunctorT&& functor, |
| 394 | uint32_t milliseconds) { |
| 395 | PostDelayed(posted_from, milliseconds, GetPostTaskMessageHandler(), |
| 396 | /*id=*/0, |
| 397 | new rtc_thread_internal::MessageWithFunctor<FunctorT>( |
| 398 | std::forward<FunctorT>(functor))); |
| 399 | } |
Henrik Boström | ba4dcc3 | 2019-02-28 09:34:06 +0100 | [diff] [blame] | 400 | |
Danil Chapovalov | 912b3b8 | 2019-11-22 15:52:40 +0100 | [diff] [blame] | 401 | // From TaskQueueBase |
| 402 | void PostTask(std::unique_ptr<webrtc::QueuedTask> task) override; |
| 403 | void PostDelayedTask(std::unique_ptr<webrtc::QueuedTask> task, |
| 404 | uint32_t milliseconds) override; |
| 405 | void Delete() override; |
| 406 | |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 407 | // ProcessMessages will process I/O and dispatch messages until: |
| 408 | // 1) cms milliseconds have elapsed (returns true) |
| 409 | // 2) Stop() is called (returns false) |
| 410 | bool ProcessMessages(int cms); |
| 411 | |
| 412 | // Returns true if this is a thread that we created using the standard |
| 413 | // constructor, false if it was created by a call to |
| 414 | // ThreadManager::WrapCurrentThread(). The main thread of an application |
| 415 | // is generally not owned, since the OS representation of the thread |
| 416 | // obviously exists before we can get to it. |
| 417 | // You cannot call Start on non-owned threads. |
| 418 | bool IsOwned(); |
| 419 | |
Tommi | 5149242 | 2017-12-04 15:18:23 +0100 | [diff] [blame] | 420 | // Expose private method IsRunning() for tests. |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 421 | // |
| 422 | // DANGER: this is a terrible public API. Most callers that might want to |
| 423 | // call this likely do not have enough control/knowledge of the Thread in |
| 424 | // question to guarantee that the returned value remains true for the duration |
| 425 | // of whatever code is conditionally executing because of the return value! |
Tommi | 5149242 | 2017-12-04 15:18:23 +0100 | [diff] [blame] | 426 | bool RunningForTest() { return IsRunning(); } |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 427 | |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 428 | // These functions are public to avoid injecting test hooks. Don't call them |
| 429 | // outside of tests. |
| 430 | // This method should be called when thread is created using non standard |
| 431 | // method, like derived implementation of rtc::Thread and it can not be |
| 432 | // started by calling Start(). This will set started flag to true and |
| 433 | // owned to false. This must be called from the current thread. |
| 434 | bool WrapCurrent(); |
| 435 | void UnwrapCurrent(); |
| 436 | |
Karl Wiberg | 3256225 | 2019-02-21 13:38:30 +0100 | [diff] [blame] | 437 | // Sets the per-thread allow-blocking-calls flag to false; this is |
| 438 | // irrevocable. Must be called on this thread. |
| 439 | void DisallowBlockingCalls() { SetAllowBlockingCalls(false); } |
| 440 | |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 441 | protected: |
Sebastian Jansson | 6ce033a | 2020-01-22 10:12:56 +0100 | [diff] [blame] | 442 | class CurrentThreadSetter : CurrentTaskQueueSetter { |
| 443 | public: |
| 444 | explicit CurrentThreadSetter(Thread* thread) |
| 445 | : CurrentTaskQueueSetter(thread), |
| 446 | manager_(rtc::ThreadManager::Instance()), |
| 447 | previous_(manager_->CurrentThread()) { |
| 448 | manager_->ChangeCurrentThreadForTest(thread); |
| 449 | } |
| 450 | ~CurrentThreadSetter() { manager_->ChangeCurrentThreadForTest(previous_); } |
| 451 | |
| 452 | private: |
| 453 | rtc::ThreadManager* const manager_; |
| 454 | rtc::Thread* const previous_; |
| 455 | }; |
| 456 | |
Sebastian Jansson | 61380c0 | 2020-01-17 14:46:08 +0100 | [diff] [blame] | 457 | // DelayedMessage goes into a priority queue, sorted by trigger time. Messages |
| 458 | // with the same trigger time are processed in num_ (FIFO) order. |
| 459 | class DelayedMessage { |
| 460 | public: |
| 461 | DelayedMessage(int64_t delay, |
| 462 | int64_t run_time_ms, |
| 463 | uint32_t num, |
| 464 | const Message& msg) |
| 465 | : delay_ms_(delay), |
| 466 | run_time_ms_(run_time_ms), |
| 467 | message_number_(num), |
| 468 | msg_(msg) {} |
| 469 | |
| 470 | bool operator<(const DelayedMessage& dmsg) const { |
| 471 | return (dmsg.run_time_ms_ < run_time_ms_) || |
| 472 | ((dmsg.run_time_ms_ == run_time_ms_) && |
| 473 | (dmsg.message_number_ < message_number_)); |
| 474 | } |
| 475 | |
| 476 | int64_t delay_ms_; // for debugging |
| 477 | int64_t run_time_ms_; |
| 478 | // Monotonicaly incrementing number used for ordering of messages |
| 479 | // targeted to execute at the same time. |
| 480 | uint32_t message_number_; |
| 481 | Message msg_; |
| 482 | }; |
| 483 | |
Sebastian Jansson | 6ea2c6a | 2020-01-13 14:07:22 +0100 | [diff] [blame] | 484 | class PriorityQueue : public std::priority_queue<DelayedMessage> { |
| 485 | public: |
| 486 | container_type& container() { return c; } |
| 487 | void reheap() { make_heap(c.begin(), c.end(), comp); } |
| 488 | }; |
| 489 | |
| 490 | void DoDelayPost(const Location& posted_from, |
| 491 | int64_t cmsDelay, |
| 492 | int64_t tstamp, |
| 493 | MessageHandler* phandler, |
| 494 | uint32_t id, |
| 495 | MessageData* pdata); |
| 496 | |
| 497 | // Perform initialization, subclasses must call this from their constructor |
| 498 | // if false was passed as init_queue to the Thread constructor. |
| 499 | void DoInit(); |
| 500 | |
| 501 | // Does not take any lock. Must be called either while holding crit_, or by |
| 502 | // the destructor (by definition, the latter has exclusive access). |
| 503 | void ClearInternal(MessageHandler* phandler, |
| 504 | uint32_t id, |
| 505 | MessageList* removed) RTC_EXCLUSIVE_LOCKS_REQUIRED(&crit_); |
| 506 | |
| 507 | // Perform cleanup; subclasses must call this from the destructor, |
| 508 | // and are not expected to actually hold the lock. |
| 509 | void DoDestroy() RTC_EXCLUSIVE_LOCKS_REQUIRED(&crit_); |
| 510 | |
| 511 | void WakeUpSocketServer(); |
| 512 | |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 513 | // Same as WrapCurrent except that it never fails as it does not try to |
| 514 | // acquire the synchronization access of the thread. The caller should never |
| 515 | // call Stop() or Join() on this thread. |
| 516 | void SafeWrapCurrent(); |
| 517 | |
| 518 | // Blocks the calling thread until this thread has terminated. |
| 519 | void Join(); |
| 520 | |
| 521 | static void AssertBlockingIsAllowedOnCurrentThread(); |
| 522 | |
| 523 | friend class ScopedDisallowBlockingCalls; |
| 524 | |
Markus Handell | 3cb525b | 2020-07-16 16:16:09 +0200 | [diff] [blame] | 525 | RecursiveCriticalSection* CritForTest() { return &crit_; } |
Sebastian Jansson | 6ea2c6a | 2020-01-13 14:07:22 +0100 | [diff] [blame] | 526 | |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 527 | private: |
Danil Chapovalov | 912b3b8 | 2019-11-22 15:52:40 +0100 | [diff] [blame] | 528 | class QueuedTaskHandler final : public MessageHandler { |
| 529 | public: |
Tomas Gunnarsson | 77baeee | 2020-09-24 22:39:21 +0200 | [diff] [blame] | 530 | QueuedTaskHandler() {} |
Danil Chapovalov | 912b3b8 | 2019-11-22 15:52:40 +0100 | [diff] [blame] | 531 | void OnMessage(Message* msg) override; |
| 532 | }; |
Steve Anton | bcc1a76 | 2019-12-11 11:21:53 -0800 | [diff] [blame] | 533 | |
Karl Wiberg | 3256225 | 2019-02-21 13:38:30 +0100 | [diff] [blame] | 534 | // Sets the per-thread allow-blocking-calls flag and returns the previous |
| 535 | // value. Must be called on this thread. |
| 536 | bool SetAllowBlockingCalls(bool allow); |
| 537 | |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 538 | #if defined(WEBRTC_WIN) |
| 539 | static DWORD WINAPI PreRun(LPVOID context); |
| 540 | #else |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 541 | static void* PreRun(void* pv); |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 542 | #endif |
| 543 | |
| 544 | // ThreadManager calls this instead WrapCurrent() because |
| 545 | // ThreadManager::Instance() cannot be used while ThreadManager is |
| 546 | // being created. |
| 547 | // The method tries to get synchronization rights of the thread on Windows if |
| 548 | // |need_synchronize_access| is true. |
| 549 | bool WrapCurrentWithThreadManager(ThreadManager* thread_manager, |
| 550 | bool need_synchronize_access); |
| 551 | |
Tommi | 5149242 | 2017-12-04 15:18:23 +0100 | [diff] [blame] | 552 | // Return true if the thread is currently running. |
| 553 | bool IsRunning(); |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 554 | |
Danil Chapovalov | 8931345 | 2019-11-29 12:56:43 +0100 | [diff] [blame] | 555 | void InvokeInternal(const Location& posted_from, |
| 556 | rtc::FunctionView<void()> functor); |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 557 | |
Tommi | 6866dc7 | 2020-05-15 10:11:56 +0200 | [diff] [blame] | 558 | // Called by the ThreadManager when being set as the current thread. |
| 559 | void EnsureIsCurrentTaskQueue(); |
| 560 | |
| 561 | // Called by the ThreadManager when being unset as the current thread. |
| 562 | void ClearCurrentTaskQueue(); |
| 563 | |
Steve Anton | bcc1a76 | 2019-12-11 11:21:53 -0800 | [diff] [blame] | 564 | // Returns a static-lifetime MessageHandler which runs message with |
| 565 | // MessageLikeTask payload data. |
| 566 | static MessageHandler* GetPostTaskMessageHandler(); |
| 567 | |
Sebastian Jansson | 6ea2c6a | 2020-01-13 14:07:22 +0100 | [diff] [blame] | 568 | bool fPeekKeep_; |
| 569 | Message msgPeek_; |
Sebastian Jansson | 61380c0 | 2020-01-17 14:46:08 +0100 | [diff] [blame] | 570 | MessageList messages_ RTC_GUARDED_BY(crit_); |
| 571 | PriorityQueue delayed_messages_ RTC_GUARDED_BY(crit_); |
| 572 | uint32_t delayed_next_num_ RTC_GUARDED_BY(crit_); |
Artem Titov | dfc5f0d | 2020-07-03 12:09:26 +0200 | [diff] [blame] | 573 | #if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)) |
| 574 | std::vector<Thread*> allowed_threads_ RTC_GUARDED_BY(this); |
| 575 | bool invoke_policy_enabled_ RTC_GUARDED_BY(this) = false; |
| 576 | #endif |
Markus Handell | 3cb525b | 2020-07-16 16:16:09 +0200 | [diff] [blame] | 577 | RecursiveCriticalSection crit_; |
Sebastian Jansson | 6ea2c6a | 2020-01-13 14:07:22 +0100 | [diff] [blame] | 578 | bool fInitialized_; |
| 579 | bool fDestroyed_; |
| 580 | |
| 581 | volatile int stop_; |
| 582 | |
| 583 | // The SocketServer might not be owned by Thread. |
| 584 | SocketServer* const ss_; |
| 585 | // Used if SocketServer ownership lies with |this|. |
| 586 | std::unique_ptr<SocketServer> own_ss_; |
| 587 | |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 588 | std::string name_; |
Tommi | 5149242 | 2017-12-04 15:18:23 +0100 | [diff] [blame] | 589 | |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 590 | // TODO(tommi): Add thread checks for proper use of control methods. |
| 591 | // Ideally we should be able to just use PlatformThread. |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 592 | |
| 593 | #if defined(WEBRTC_POSIX) |
Tommi | 6cea2b0 | 2017-12-04 18:51:16 +0100 | [diff] [blame] | 594 | pthread_t thread_ = 0; |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 595 | #endif |
| 596 | |
| 597 | #if defined(WEBRTC_WIN) |
Tommi | 6cea2b0 | 2017-12-04 18:51:16 +0100 | [diff] [blame] | 598 | HANDLE thread_ = nullptr; |
| 599 | DWORD thread_id_ = 0; |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 600 | #endif |
| 601 | |
Tommi | 5149242 | 2017-12-04 15:18:23 +0100 | [diff] [blame] | 602 | // Indicates whether or not ownership of the worker thread lies with |
| 603 | // this instance or not. (i.e. owned_ == !wrapped). |
| 604 | // Must only be modified when the worker thread is not running. |
| 605 | bool owned_ = true; |
| 606 | |
| 607 | // Only touched from the worker thread itself. |
| 608 | bool blocking_calls_allowed_ = true; |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 609 | |
Danil Chapovalov | 912b3b8 | 2019-11-22 15:52:40 +0100 | [diff] [blame] | 610 | // Runs webrtc::QueuedTask posted to the Thread. |
| 611 | QueuedTaskHandler queued_task_handler_; |
Tommi | 6866dc7 | 2020-05-15 10:11:56 +0200 | [diff] [blame] | 612 | std::unique_ptr<TaskQueueBase::CurrentTaskQueueSetter> |
| 613 | task_queue_registration_; |
Danil Chapovalov | 912b3b8 | 2019-11-22 15:52:40 +0100 | [diff] [blame] | 614 | |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 615 | friend class ThreadManager; |
| 616 | |
| 617 | RTC_DISALLOW_COPY_AND_ASSIGN(Thread); |
| 618 | }; |
| 619 | |
| 620 | // AutoThread automatically installs itself at construction |
| 621 | // uninstalls at destruction, if a Thread object is |
| 622 | // _not already_ associated with the current OS thread. |
Tomas Gunnarsson | 0fd4c4e | 2020-09-04 16:33:25 +0200 | [diff] [blame] | 623 | // |
| 624 | // NOTE: *** This class should only be used by tests *** |
| 625 | // |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 626 | class AutoThread : public Thread { |
| 627 | public: |
| 628 | AutoThread(); |
| 629 | ~AutoThread() override; |
| 630 | |
| 631 | private: |
| 632 | RTC_DISALLOW_COPY_AND_ASSIGN(AutoThread); |
| 633 | }; |
| 634 | |
| 635 | // AutoSocketServerThread automatically installs itself at |
| 636 | // construction and uninstalls at destruction. If a Thread object is |
| 637 | // already associated with the current OS thread, it is temporarily |
| 638 | // disassociated and restored by the destructor. |
| 639 | |
| 640 | class AutoSocketServerThread : public Thread { |
| 641 | public: |
| 642 | explicit AutoSocketServerThread(SocketServer* ss); |
| 643 | ~AutoSocketServerThread() override; |
| 644 | |
| 645 | private: |
| 646 | rtc::Thread* old_thread_; |
| 647 | |
| 648 | RTC_DISALLOW_COPY_AND_ASSIGN(AutoSocketServerThread); |
| 649 | }; |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 650 | } // namespace rtc |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 651 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 652 | #endif // RTC_BASE_THREAD_H_ |