• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 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 "rtc_base/synchronization/rw_lock_posix.h"
12 
13 #include <stddef.h>
14 
15 namespace webrtc {
16 
RWLockPosix()17 RWLockPosix::RWLockPosix() : lock_() {}
18 
~RWLockPosix()19 RWLockPosix::~RWLockPosix() {
20   pthread_rwlock_destroy(&lock_);
21 }
22 
Create()23 RWLockPosix* RWLockPosix::Create() {
24   RWLockPosix* ret_val = new RWLockPosix();
25   if (!ret_val->Init()) {
26     delete ret_val;
27     return NULL;
28   }
29   return ret_val;
30 }
31 
Init()32 bool RWLockPosix::Init() {
33   return pthread_rwlock_init(&lock_, 0) == 0;
34 }
35 
AcquireLockExclusive()36 void RWLockPosix::AcquireLockExclusive() {
37   pthread_rwlock_wrlock(&lock_);
38 }
39 
ReleaseLockExclusive()40 void RWLockPosix::ReleaseLockExclusive() {
41   pthread_rwlock_unlock(&lock_);
42 }
43 
AcquireLockShared()44 void RWLockPosix::AcquireLockShared() {
45   pthread_rwlock_rdlock(&lock_);
46 }
47 
ReleaseLockShared()48 void RWLockPosix::ReleaseLockShared() {
49   pthread_rwlock_unlock(&lock_);
50 }
51 
52 }  // namespace webrtc
53