blob: fcad5c31d6aebef33b1a42590497449b2f18fcb4 [file] [log] [blame]
Jiayang Liubef8d2d2015-03-26 14:38:46 -07001/*
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
16namespace rtc {
17
18void GlobalLockPod::Lock() {
19 while (AtomicOps::CompareAndSwap(&lock_acquired, 0, 1)) {
20 Thread::SleepMs(0);
21 }
22}
23
24void 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
29GlobalLock::GlobalLock() {
30 lock_acquired = 0;
31}
32
33} // namespace rtc