| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 | 61 |
| 62 private: | 62 private: |
| 63 #if defined(WEBRTC_POSIX) | 63 #if defined(WEBRTC_POSIX) |
| 64 pthread_key_t key_; | 64 pthread_key_t key_; |
| 65 #endif | 65 #endif |
| 66 | 66 |
| 67 #if defined(WEBRTC_WIN) | 67 #if defined(WEBRTC_WIN) |
| 68 DWORD key_; | 68 DWORD key_; |
| 69 #endif | 69 #endif |
| 70 | 70 |
| 71 DISALLOW_COPY_AND_ASSIGN(ThreadManager); | 71 RTC_DISALLOW_COPY_AND_ASSIGN(ThreadManager); |
| 72 }; | 72 }; |
| 73 | 73 |
| 74 struct _SendMessage { | 74 struct _SendMessage { |
| 75 _SendMessage() {} | 75 _SendMessage() {} |
| 76 Thread *thread; | 76 Thread *thread; |
| 77 Message msg; | 77 Message msg; |
| 78 bool *ready; | 78 bool *ready; |
| 79 }; | 79 }; |
| 80 | 80 |
| 81 enum ThreadPriority { | 81 enum ThreadPriority { |
| 82 PRIORITY_IDLE = -1, | 82 PRIORITY_IDLE = -1, |
| 83 PRIORITY_NORMAL = 0, | 83 PRIORITY_NORMAL = 0, |
| 84 PRIORITY_ABOVE_NORMAL = 1, | 84 PRIORITY_ABOVE_NORMAL = 1, |
| 85 PRIORITY_HIGH = 2, | 85 PRIORITY_HIGH = 2, |
| 86 }; | 86 }; |
| 87 | 87 |
| 88 class Runnable { | 88 class Runnable { |
| 89 public: | 89 public: |
| 90 virtual ~Runnable() {} | 90 virtual ~Runnable() {} |
| 91 virtual void Run(Thread* thread) = 0; | 91 virtual void Run(Thread* thread) = 0; |
| 92 | 92 |
| 93 protected: | 93 protected: |
| 94 Runnable() {} | 94 Runnable() {} |
| 95 | 95 |
| 96 private: | 96 private: |
| 97 DISALLOW_COPY_AND_ASSIGN(Runnable); | 97 RTC_DISALLOW_COPY_AND_ASSIGN(Runnable); |
| 98 }; | 98 }; |
| 99 | 99 |
| 100 // WARNING! SUBCLASSES MUST CALL Stop() IN THEIR DESTRUCTORS! See ~Thread(). | 100 // WARNING! SUBCLASSES MUST CALL Stop() IN THEIR DESTRUCTORS! See ~Thread(). |
| 101 | 101 |
| 102 class Thread : public MessageQueue { | 102 class Thread : public MessageQueue { |
| 103 public: | 103 public: |
| 104 explicit Thread(SocketServer* ss = NULL); | 104 explicit Thread(SocketServer* ss = NULL); |
| 105 // 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 |
| 106 // guarantee Stop() is explicitly called before the subclass is destroyed). | 106 // guarantee Stop() is explicitly called before the subclass is destroyed). |
| 107 // 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 |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 #if defined(WEBRTC_WIN) | 280 #if defined(WEBRTC_WIN) |
| 281 HANDLE thread_; | 281 HANDLE thread_; |
| 282 DWORD thread_id_; | 282 DWORD thread_id_; |
| 283 #endif | 283 #endif |
| 284 | 284 |
| 285 bool owned_; | 285 bool owned_; |
| 286 bool blocking_calls_allowed_; // By default set to |true|. | 286 bool blocking_calls_allowed_; // By default set to |true|. |
| 287 | 287 |
| 288 friend class ThreadManager; | 288 friend class ThreadManager; |
| 289 | 289 |
| 290 DISALLOW_COPY_AND_ASSIGN(Thread); | 290 RTC_DISALLOW_COPY_AND_ASSIGN(Thread); |
| 291 }; | 291 }; |
| 292 | 292 |
| 293 // AutoThread automatically installs itself at construction | 293 // AutoThread automatically installs itself at construction |
| 294 // uninstalls at destruction, if a Thread object is | 294 // uninstalls at destruction, if a Thread object is |
| 295 // _not already_ associated with the current OS thread. | 295 // _not already_ associated with the current OS thread. |
| 296 | 296 |
| 297 class AutoThread : public Thread { | 297 class AutoThread : public Thread { |
| 298 public: | 298 public: |
| 299 explicit AutoThread(SocketServer* ss = 0); | 299 explicit AutoThread(SocketServer* ss = 0); |
| 300 ~AutoThread() override; | 300 ~AutoThread() override; |
| 301 | 301 |
| 302 private: | 302 private: |
| 303 DISALLOW_COPY_AND_ASSIGN(AutoThread); | 303 RTC_DISALLOW_COPY_AND_ASSIGN(AutoThread); |
| 304 }; | 304 }; |
| 305 | 305 |
| 306 // Win32 extension for threads that need to use COM | 306 // Win32 extension for threads that need to use COM |
| 307 #if defined(WEBRTC_WIN) | 307 #if defined(WEBRTC_WIN) |
| 308 class ComThread : public Thread { | 308 class ComThread : public Thread { |
| 309 public: | 309 public: |
| 310 ComThread() {} | 310 ComThread() {} |
| 311 virtual ~ComThread() { Stop(); } | 311 virtual ~ComThread() { Stop(); } |
| 312 | 312 |
| 313 protected: | 313 protected: |
| 314 virtual void Run(); | 314 virtual void Run(); |
| 315 | 315 |
| 316 private: | 316 private: |
| 317 DISALLOW_COPY_AND_ASSIGN(ComThread); | 317 RTC_DISALLOW_COPY_AND_ASSIGN(ComThread); |
| 318 }; | 318 }; |
| 319 #endif | 319 #endif |
| 320 | 320 |
| 321 // Provides an easy way to install/uninstall a socketserver on a thread. | 321 // Provides an easy way to install/uninstall a socketserver on a thread. |
| 322 class SocketServerScope { | 322 class SocketServerScope { |
| 323 public: | 323 public: |
| 324 explicit SocketServerScope(SocketServer* ss) { | 324 explicit SocketServerScope(SocketServer* ss) { |
| 325 old_ss_ = Thread::Current()->socketserver(); | 325 old_ss_ = Thread::Current()->socketserver(); |
| 326 Thread::Current()->set_socketserver(ss); | 326 Thread::Current()->set_socketserver(ss); |
| 327 } | 327 } |
| 328 ~SocketServerScope() { | 328 ~SocketServerScope() { |
| 329 Thread::Current()->set_socketserver(old_ss_); | 329 Thread::Current()->set_socketserver(old_ss_); |
| 330 } | 330 } |
| 331 | 331 |
| 332 private: | 332 private: |
| 333 SocketServer* old_ss_; | 333 SocketServer* old_ss_; |
| 334 | 334 |
| 335 DISALLOW_IMPLICIT_CONSTRUCTORS(SocketServerScope); | 335 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(SocketServerScope); |
| 336 }; | 336 }; |
| 337 | 337 |
| 338 } // namespace rtc | 338 } // namespace rtc |
| 339 | 339 |
| 340 #endif // WEBRTC_BASE_THREAD_H_ | 340 #endif // WEBRTC_BASE_THREAD_H_ |
| OLD | NEW |