Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2015 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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 bool TryCritScope::locked() const { | 132 bool TryCritScope::locked() const { |
| 133 CS_DEBUG_CODE(lock_was_called_ = true); | 133 CS_DEBUG_CODE(lock_was_called_ = true); |
| 134 return locked_; | 134 return locked_; |
| 135 } | 135 } |
| 136 | 136 |
| 137 void GlobalLockPod::Lock() { | 137 void GlobalLockPod::Lock() { |
| 138 #if !defined(WEBRTC_WIN) | 138 #if !defined(WEBRTC_WIN) |
| 139 const struct timespec ts_null = {0}; | 139 const struct timespec ts_null = {0}; |
| 140 #endif | 140 #endif |
| 141 | 141 |
| 142 while (AtomicOps::CompareAndSwap(&lock_acquired, 0, 1)) { | 142 while (AtomicInt::CompareAndSwap(&lock_acquired, 0, 1)) { |
| 143 #if defined(WEBRTC_WIN) | 143 #if defined(WEBRTC_WIN) |
| 144 ::Sleep(0); | 144 ::Sleep(0); |
| 145 #else | 145 #else |
| 146 nanosleep(&ts_null, nullptr); | 146 nanosleep(&ts_null, nullptr); |
| 147 #endif | 147 #endif |
| 148 } | 148 } |
| 149 } | 149 } |
| 150 | 150 |
| 151 void GlobalLockPod::Unlock() { | 151 void GlobalLockPod::Unlock() { |
| 152 int old_value = AtomicOps::CompareAndSwap(&lock_acquired, 1, 0); | 152 int old_value = AtomicInt::CompareAndSwap(&lock_acquired, 1, 0); |
| 153 RTC_DCHECK_EQ(1, old_value) << "Unlock called without calling Lock first"; | 153 RTC_DCHECK_EQ(1, old_value) << "Unlock called without calling Lock first"; |
| 154 } | 154 } |
| 155 | 155 |
| 156 GlobalLock::GlobalLock() { | 156 GlobalLock::GlobalLock() : GlobalLockPod({{0}}) {} |
|
tommi
2015/11/06 22:53:36
I guess you've talked about having a default ctor?
| |
| 157 lock_acquired = 0; | |
| 158 } | |
| 159 | 157 |
| 160 GlobalLockScope::GlobalLockScope(GlobalLockPod* lock) | 158 GlobalLockScope::GlobalLockScope(GlobalLockPod* lock) : lock_(lock) { |
| 161 : lock_(lock) { | |
| 162 lock_->Lock(); | 159 lock_->Lock(); |
| 163 } | 160 } |
| 164 | 161 |
| 165 GlobalLockScope::~GlobalLockScope() { | 162 GlobalLockScope::~GlobalLockScope() { |
| 166 lock_->Unlock(); | 163 lock_->Unlock(); |
| 167 } | 164 } |
| 168 | 165 |
| 169 } // namespace rtc | 166 } // namespace rtc |
| OLD | NEW |