Chromium Code Reviews| 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 // Create a new Thread and optionally assign it to the passed SocketServer. | 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 | 98 // Subclasses that override Clear should pass false for init_queue and call |
| 99 // DoInit() from their constructor to prevent races with the | 99 // DoInit() from their constructor to prevent races with the |
| 100 // MessageQueueManager already using the object while the vtable is still | 100 // MessageQueueManager already using the object while the vtable is still |
| 101 // being created. | 101 // being created. |
| 102 explicit Thread(SocketServer* ss = nullptr, bool init_queue = true); | 102 Thread(); |
| 103 explicit Thread(SocketServer* ss); | |
|
tommi
2016/04/27 12:45:25
Down the line, I think it would be good if the soc
danilchap
2016/04/27 15:08:55
I see this cl as a small step towards that goal.
| |
| 103 | 104 |
| 104 // NOTE: ALL SUBCLASSES OF Thread MUST CALL Stop() IN THEIR DESTRUCTORS (or | 105 // NOTE: ALL SUBCLASSES OF Thread MUST CALL Stop() IN THEIR DESTRUCTORS (or |
| 105 // guarantee Stop() is explicitly called before the subclass is destroyed). | 106 // guarantee Stop() is explicitly called before the subclass is destroyed). |
| 106 // This is required to avoid a data race between the destructor modifying the | 107 // This is required to avoid a data race between the destructor modifying the |
| 107 // vtable, and the Thread::PreRun calling the virtual method Run(). | 108 // vtable, and the Thread::PreRun calling the virtual method Run(). |
| 108 ~Thread() override; | 109 ~Thread() override; |
| 109 | 110 |
| 111 static std::unique_ptr<Thread> CreateWithSocketServer(); | |
| 112 static std::unique_ptr<Thread> Create(); | |
| 110 static Thread* Current(); | 113 static Thread* Current(); |
| 111 | 114 |
| 112 // Used to catch performance regressions. Use this to disallow blocking calls | 115 // Used to catch performance regressions. Use this to disallow blocking calls |
| 113 // (Invoke) for a given scope. If a synchronous call is made while this is in | 116 // (Invoke) for a given scope. If a synchronous call is made while this is in |
| 114 // effect, an assert will be triggered. | 117 // effect, an assert will be triggered. |
| 115 // Note that this is a single threaded class. | 118 // Note that this is a single threaded class. |
| 116 class ScopedDisallowBlockingCalls { | 119 class ScopedDisallowBlockingCalls { |
| 117 public: | 120 public: |
| 118 ScopedDisallowBlockingCalls(); | 121 ScopedDisallowBlockingCalls(); |
| 119 ~ScopedDisallowBlockingCalls(); | 122 ~ScopedDisallowBlockingCalls(); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 217 // These functions are public to avoid injecting test hooks. Don't call them | 220 // These functions are public to avoid injecting test hooks. Don't call them |
| 218 // outside of tests. | 221 // outside of tests. |
| 219 // This method should be called when thread is created using non standard | 222 // This method should be called when thread is created using non standard |
| 220 // method, like derived implementation of rtc::Thread and it can not be | 223 // method, like derived implementation of rtc::Thread and it can not be |
| 221 // started by calling Start(). This will set started flag to true and | 224 // started by calling Start(). This will set started flag to true and |
| 222 // owned to false. This must be called from the current thread. | 225 // owned to false. This must be called from the current thread. |
| 223 bool WrapCurrent(); | 226 bool WrapCurrent(); |
| 224 void UnwrapCurrent(); | 227 void UnwrapCurrent(); |
| 225 | 228 |
| 226 protected: | 229 protected: |
| 230 Thread(SocketServer* ss, bool init_queue); | |
| 231 Thread(std::unique_ptr<SocketServer> ss, bool init_queue); | |
| 232 | |
| 227 // Same as WrapCurrent except that it never fails as it does not try to | 233 // Same as WrapCurrent except that it never fails as it does not try to |
| 228 // acquire the synchronization access of the thread. The caller should never | 234 // acquire the synchronization access of the thread. The caller should never |
| 229 // call Stop() or Join() on this thread. | 235 // call Stop() or Join() on this thread. |
| 230 void SafeWrapCurrent(); | 236 void SafeWrapCurrent(); |
| 231 | 237 |
| 232 // Blocks the calling thread until this thread has terminated. | 238 // Blocks the calling thread until this thread has terminated. |
| 233 void Join(); | 239 void Join(); |
| 234 | 240 |
| 235 static void AssertBlockingIsAllowedOnCurrentThread(); | 241 static void AssertBlockingIsAllowedOnCurrentThread(); |
| 236 | 242 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 284 | 290 |
| 285 RTC_DISALLOW_COPY_AND_ASSIGN(Thread); | 291 RTC_DISALLOW_COPY_AND_ASSIGN(Thread); |
| 286 }; | 292 }; |
| 287 | 293 |
| 288 // AutoThread automatically installs itself at construction | 294 // AutoThread automatically installs itself at construction |
| 289 // uninstalls at destruction, if a Thread object is | 295 // uninstalls at destruction, if a Thread object is |
| 290 // _not already_ associated with the current OS thread. | 296 // _not already_ associated with the current OS thread. |
| 291 | 297 |
| 292 class AutoThread : public Thread { | 298 class AutoThread : public Thread { |
| 293 public: | 299 public: |
| 294 explicit AutoThread(SocketServer* ss = nullptr); | 300 AutoThread(); |
| 295 ~AutoThread() override; | 301 ~AutoThread() override; |
| 296 | 302 |
| 297 private: | 303 private: |
| 298 RTC_DISALLOW_COPY_AND_ASSIGN(AutoThread); | 304 RTC_DISALLOW_COPY_AND_ASSIGN(AutoThread); |
| 299 }; | 305 }; |
| 300 | 306 |
| 301 // Win32 extension for threads that need to use COM | 307 // Win32 extension for threads that need to use COM |
| 302 #if defined(WEBRTC_WIN) | 308 #if defined(WEBRTC_WIN) |
| 303 class ComThread : public Thread { | 309 class ComThread : public Thread { |
| 304 public: | 310 public: |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 326 | 332 |
| 327 private: | 333 private: |
| 328 SocketServer* old_ss_; | 334 SocketServer* old_ss_; |
| 329 | 335 |
| 330 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(SocketServerScope); | 336 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(SocketServerScope); |
| 331 }; | 337 }; |
| 332 | 338 |
| 333 } // namespace rtc | 339 } // namespace rtc |
| 334 | 340 |
| 335 #endif // WEBRTC_BASE_THREAD_H_ | 341 #endif // WEBRTC_BASE_THREAD_H_ |
| OLD | NEW |