This reverts commit 5831afb8328cbecdbdbee882280ef907a09d9f31. Reason for revert: The code is still in use: https://ci.chromium.org/ui/p/webrtc/builders/ci/Win32%20Builder%20(Clang)/10243/overview. It wasn't detected for some reasons. Original change's description: > Delete unused class GlobalMutex > > Bug: webrtc:13869 > Change-Id: Id3655bdd24630b78e83b606291605a37129fd4bc > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/258131 > Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> > Commit-Queue: Niels Moller <nisse@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#36478} Bug: webrtc:13869 Change-Id: Id44dd4f8ec31ac9e05fc0ee75b55916e627fd7bf No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/258135 Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> Owners-Override: Artem Titov <titovartem@webrtc.org> Commit-Queue: Artem Titov <titovartem@webrtc.org> Cr-Commit-Position: refs/heads/main@{#36480}
40 lines
1.0 KiB
C++
40 lines
1.0 KiB
C++
/*
|
|
* Copyright 2020 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 "rtc_base/synchronization/mutex.h"
|
|
|
|
#include "rtc_base/checks.h"
|
|
#include "rtc_base/synchronization/yield.h"
|
|
|
|
namespace webrtc {
|
|
|
|
#if !defined(WEBRTC_ABSL_MUTEX)
|
|
void GlobalMutex::Lock() {
|
|
while (mutex_locked_.exchange(1)) {
|
|
YieldCurrentThread();
|
|
}
|
|
}
|
|
|
|
void GlobalMutex::Unlock() {
|
|
int old = mutex_locked_.exchange(0);
|
|
RTC_DCHECK_EQ(old, 1) << "Unlock called without calling Lock first";
|
|
}
|
|
|
|
GlobalMutexLock::GlobalMutexLock(GlobalMutex* mutex) : mutex_(mutex) {
|
|
mutex_->Lock();
|
|
}
|
|
|
|
GlobalMutexLock::~GlobalMutexLock() {
|
|
mutex_->Unlock();
|
|
}
|
|
#endif // #if !defined(WEBRTC_ABSL_MUTEX)
|
|
|
|
} // namespace webrtc
|