| 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 |
| 11 #include "webrtc/base/signalthread.h" | 11 #include "webrtc/base/signalthread.h" |
| 12 | 12 |
| 13 #include "webrtc/base/checks.h" |
| 13 #include "webrtc/base/common.h" | 14 #include "webrtc/base/common.h" |
| 14 | 15 |
| 15 namespace rtc { | 16 namespace rtc { |
| 16 | 17 |
| 17 /////////////////////////////////////////////////////////////////////////////// | 18 /////////////////////////////////////////////////////////////////////////////// |
| 18 // SignalThread | 19 // SignalThread |
| 19 /////////////////////////////////////////////////////////////////////////////// | 20 /////////////////////////////////////////////////////////////////////////////// |
| 20 | 21 |
| 21 SignalThread::SignalThread(bool use_socket_server) | 22 SignalThread::SignalThread(bool use_socket_server) |
| 22 : main_(Thread::Current()), | 23 : main_(Thread::Current()), |
| (...skipping 17 matching lines...) Expand all Loading... |
| 40 } | 41 } |
| 41 | 42 |
| 42 void SignalThread::Start() { | 43 void SignalThread::Start() { |
| 43 EnterExit ee(this); | 44 EnterExit ee(this); |
| 44 ASSERT(main_->IsCurrent()); | 45 ASSERT(main_->IsCurrent()); |
| 45 if (kInit == state_ || kComplete == state_) { | 46 if (kInit == state_ || kComplete == state_) { |
| 46 state_ = kRunning; | 47 state_ = kRunning; |
| 47 OnWorkStart(); | 48 OnWorkStart(); |
| 48 worker_.Start(); | 49 worker_.Start(); |
| 49 } else { | 50 } else { |
| 50 ASSERT(false); | 51 RTC_NOTREACHED(); |
| 51 } | 52 } |
| 52 } | 53 } |
| 53 | 54 |
| 54 void SignalThread::Destroy(bool wait) { | 55 void SignalThread::Destroy(bool wait) { |
| 55 EnterExit ee(this); | 56 EnterExit ee(this); |
| 56 ASSERT(main_->IsCurrent()); | 57 ASSERT(main_->IsCurrent()); |
| 57 if ((kInit == state_) || (kComplete == state_)) { | 58 if ((kInit == state_) || (kComplete == state_)) { |
| 58 refcount_--; | 59 refcount_--; |
| 59 } else if (kRunning == state_ || kReleasing == state_) { | 60 } else if (kRunning == state_ || kReleasing == state_) { |
| 60 state_ = kStopping; | 61 state_ = kStopping; |
| 61 // OnWorkStop() must follow Quit(), so that when the thread wakes up due to | 62 // OnWorkStop() must follow Quit(), so that when the thread wakes up due to |
| 62 // OWS(), ContinueWork() will return false. | 63 // OWS(), ContinueWork() will return false. |
| 63 worker_.Quit(); | 64 worker_.Quit(); |
| 64 OnWorkStop(); | 65 OnWorkStop(); |
| 65 if (wait) { | 66 if (wait) { |
| 66 // Release the thread's lock so that it can return from ::Run. | 67 // Release the thread's lock so that it can return from ::Run. |
| 67 cs_.Leave(); | 68 cs_.Leave(); |
| 68 worker_.Stop(); | 69 worker_.Stop(); |
| 69 cs_.Enter(); | 70 cs_.Enter(); |
| 70 refcount_--; | 71 refcount_--; |
| 71 } | 72 } |
| 72 } else { | 73 } else { |
| 73 ASSERT(false); | 74 RTC_NOTREACHED(); |
| 74 } | 75 } |
| 75 } | 76 } |
| 76 | 77 |
| 77 void SignalThread::Release() { | 78 void SignalThread::Release() { |
| 78 EnterExit ee(this); | 79 EnterExit ee(this); |
| 79 ASSERT(main_->IsCurrent()); | 80 ASSERT(main_->IsCurrent()); |
| 80 if (kComplete == state_) { | 81 if (kComplete == state_) { |
| 81 refcount_--; | 82 refcount_--; |
| 82 } else if (kRunning == state_) { | 83 } else if (kRunning == state_) { |
| 83 state_ = kReleasing; | 84 state_ = kReleasing; |
| 84 } else { | 85 } else { |
| 85 // if (kInit == state_) use Destroy() | 86 // if (kInit == state_) use Destroy() |
| 86 ASSERT(false); | 87 RTC_NOTREACHED(); |
| 87 } | 88 } |
| 88 } | 89 } |
| 89 | 90 |
| 90 bool SignalThread::ContinueWork() { | 91 bool SignalThread::ContinueWork() { |
| 91 EnterExit ee(this); | 92 EnterExit ee(this); |
| 92 ASSERT(worker_.IsCurrent()); | 93 ASSERT(worker_.IsCurrent()); |
| 93 return worker_.ProcessMessages(0); | 94 return worker_.ProcessMessages(0); |
| 94 } | 95 } |
| 95 | 96 |
| 96 void SignalThread::OnMessage(Message *msg) { | 97 void SignalThread::OnMessage(Message *msg) { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 } | 142 } |
| 142 } | 143 } |
| 143 } | 144 } |
| 144 | 145 |
| 145 void SignalThread::OnMainThreadDestroyed() { | 146 void SignalThread::OnMainThreadDestroyed() { |
| 146 EnterExit ee(this); | 147 EnterExit ee(this); |
| 147 main_ = NULL; | 148 main_ = NULL; |
| 148 } | 149 } |
| 149 | 150 |
| 150 } // namespace rtc | 151 } // namespace rtc |
| OLD | NEW |