Files
webrtc/webrtc/base/criticalsection.cc
Jiayang Liu bef8d2d020 Add a lock to NSSContext to fix data race
BUG=crbug/466784
R=juberti@webrtc.org, tommi@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/44669005

Cr-Commit-Position: refs/heads/master@{#8871}
2015-03-26 21:38:53 +00:00

34 lines
899 B
C++

/*
* Copyright 2015 The WebRTC Project Authors. All rights reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "webrtc/base/criticalsection.h"
#include "webrtc/base/checks.h"
#include "webrtc/base/thread.h"
namespace rtc {
void GlobalLockPod::Lock() {
while (AtomicOps::CompareAndSwap(&lock_acquired, 0, 1)) {
Thread::SleepMs(0);
}
}
void GlobalLockPod::Unlock() {
int old_value = AtomicOps::CompareAndSwap(&lock_acquired, 1, 0);
DCHECK_EQ(1, old_value) << "Unlock called without calling Lock first";
}
GlobalLock::GlobalLock() {
lock_acquired = 0;
}
} // namespace rtc