Jiayang Liu | bef8d2d | 2015-03-26 14:38:46 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2015 The WebRTC Project Authors. All rights reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #include "webrtc/base/criticalsection.h" |
| 12 | |
| 13 | #include "webrtc/base/checks.h" |
| 14 | #include "webrtc/base/thread.h" |
| 15 | |
| 16 | namespace rtc { |
| 17 | |
| 18 | void GlobalLockPod::Lock() { |
| 19 | while (AtomicOps::CompareAndSwap(&lock_acquired, 0, 1)) { |
| 20 | Thread::SleepMs(0); |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | void GlobalLockPod::Unlock() { |
| 25 | int old_value = AtomicOps::CompareAndSwap(&lock_acquired, 1, 0); |
| 26 | DCHECK_EQ(1, old_value) << "Unlock called without calling Lock first"; |
| 27 | } |
| 28 | |
| 29 | GlobalLock::GlobalLock() { |
| 30 | lock_acquired = 0; |
| 31 | } |
| 32 | |
| 33 | } // namespace rtc |