OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 Runnable() {} | 87 Runnable() {} |
88 | 88 |
89 private: | 89 private: |
90 RTC_DISALLOW_COPY_AND_ASSIGN(Runnable); | 90 RTC_DISALLOW_COPY_AND_ASSIGN(Runnable); |
91 }; | 91 }; |
92 | 92 |
93 // WARNING! SUBCLASSES MUST CALL Stop() IN THEIR DESTRUCTORS! See ~Thread(). | 93 // WARNING! SUBCLASSES MUST CALL Stop() IN THEIR DESTRUCTORS! See ~Thread(). |
94 | 94 |
95 class Thread : public MessageQueue { | 95 class Thread : public MessageQueue { |
96 public: | 96 public: |
97 explicit Thread(SocketServer* ss = NULL); | 97 // Create a new Thread and optionally assign it to the passed SocketServer. |
| 98 // Subclasses that override Clear should pass false for init_queue and call |
| 99 // DoInit() from their constructor to prevent races with the |
| 100 // MessageQueueManager already using the object while the vtable is still |
| 101 // being created. |
| 102 explicit Thread(SocketServer* ss = nullptr, bool init_queue = true); |
| 103 |
98 // NOTE: ALL SUBCLASSES OF Thread MUST CALL Stop() IN THEIR DESTRUCTORS (or | 104 // NOTE: ALL SUBCLASSES OF Thread MUST CALL Stop() IN THEIR DESTRUCTORS (or |
99 // guarantee Stop() is explicitly called before the subclass is destroyed). | 105 // guarantee Stop() is explicitly called before the subclass is destroyed). |
100 // This is required to avoid a data race between the destructor modifying the | 106 // This is required to avoid a data race between the destructor modifying the |
101 // vtable, and the Thread::PreRun calling the virtual method Run(). | 107 // vtable, and the Thread::PreRun calling the virtual method Run(). |
102 ~Thread() override; | 108 ~Thread() override; |
103 | 109 |
104 static Thread* Current(); | 110 static Thread* Current(); |
105 | 111 |
106 // Used to catch performance regressions. Use this to disallow blocking calls | 112 // Used to catch performance regressions. Use this to disallow blocking calls |
107 // (Invoke) for a given scope. If a synchronous call is made while this is in | 113 // (Invoke) for a given scope. If a synchronous call is made while this is in |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 | 284 |
279 RTC_DISALLOW_COPY_AND_ASSIGN(Thread); | 285 RTC_DISALLOW_COPY_AND_ASSIGN(Thread); |
280 }; | 286 }; |
281 | 287 |
282 // AutoThread automatically installs itself at construction | 288 // AutoThread automatically installs itself at construction |
283 // uninstalls at destruction, if a Thread object is | 289 // uninstalls at destruction, if a Thread object is |
284 // _not already_ associated with the current OS thread. | 290 // _not already_ associated with the current OS thread. |
285 | 291 |
286 class AutoThread : public Thread { | 292 class AutoThread : public Thread { |
287 public: | 293 public: |
288 explicit AutoThread(SocketServer* ss = 0); | 294 explicit AutoThread(SocketServer* ss = nullptr); |
289 ~AutoThread() override; | 295 ~AutoThread() override; |
290 | 296 |
291 private: | 297 private: |
292 RTC_DISALLOW_COPY_AND_ASSIGN(AutoThread); | 298 RTC_DISALLOW_COPY_AND_ASSIGN(AutoThread); |
293 }; | 299 }; |
294 | 300 |
295 // Win32 extension for threads that need to use COM | 301 // Win32 extension for threads that need to use COM |
296 #if defined(WEBRTC_WIN) | 302 #if defined(WEBRTC_WIN) |
297 class ComThread : public Thread { | 303 class ComThread : public Thread { |
298 public: | 304 public: |
299 ComThread() {} | 305 ComThread() {} |
300 virtual ~ComThread() { Stop(); } | 306 ~ComThread() override { Stop(); } |
301 | 307 |
302 protected: | 308 protected: |
303 virtual void Run(); | 309 void Run() override; |
304 | 310 |
305 private: | 311 private: |
306 RTC_DISALLOW_COPY_AND_ASSIGN(ComThread); | 312 RTC_DISALLOW_COPY_AND_ASSIGN(ComThread); |
307 }; | 313 }; |
308 #endif | 314 #endif |
309 | 315 |
310 // Provides an easy way to install/uninstall a socketserver on a thread. | 316 // Provides an easy way to install/uninstall a socketserver on a thread. |
311 class SocketServerScope { | 317 class SocketServerScope { |
312 public: | 318 public: |
313 explicit SocketServerScope(SocketServer* ss) { | 319 explicit SocketServerScope(SocketServer* ss) { |
314 old_ss_ = Thread::Current()->socketserver(); | 320 old_ss_ = Thread::Current()->socketserver(); |
315 Thread::Current()->set_socketserver(ss); | 321 Thread::Current()->set_socketserver(ss); |
316 } | 322 } |
317 ~SocketServerScope() { | 323 ~SocketServerScope() { |
318 Thread::Current()->set_socketserver(old_ss_); | 324 Thread::Current()->set_socketserver(old_ss_); |
319 } | 325 } |
320 | 326 |
321 private: | 327 private: |
322 SocketServer* old_ss_; | 328 SocketServer* old_ss_; |
323 | 329 |
324 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(SocketServerScope); | 330 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(SocketServerScope); |
325 }; | 331 }; |
326 | 332 |
327 } // namespace rtc | 333 } // namespace rtc |
328 | 334 |
329 #endif // WEBRTC_BASE_THREAD_H_ | 335 #endif // WEBRTC_BASE_THREAD_H_ |
OLD | NEW |