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