• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright 2011 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/sharedexclusivelock.h"
12 
13 namespace rtc {
14 
SharedExclusiveLock()15 SharedExclusiveLock::SharedExclusiveLock()
16     : shared_count_is_zero_(true, true),
17       shared_count_(0) {
18 }
19 
LockExclusive()20 void SharedExclusiveLock::LockExclusive() {
21   cs_exclusive_.Enter();
22   shared_count_is_zero_.Wait(Event::kForever);
23 }
24 
UnlockExclusive()25 void SharedExclusiveLock::UnlockExclusive() {
26   cs_exclusive_.Leave();
27 }
28 
LockShared()29 void SharedExclusiveLock::LockShared() {
30   CritScope exclusive_scope(&cs_exclusive_);
31   CritScope shared_scope(&cs_shared_);
32   if (++shared_count_ == 1) {
33     shared_count_is_zero_.Reset();
34   }
35 }
36 
UnlockShared()37 void SharedExclusiveLock::UnlockShared() {
38   CritScope shared_scope(&cs_shared_);
39   if (--shared_count_ == 0) {
40     shared_count_is_zero_.Set();
41   }
42 }
43 
44 }  // namespace rtc
45