niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
phoglund@webrtc.org | 59ad541 | 2012-12-18 15:20:35 +0000 | [diff] [blame] | 11 | #include "webrtc/system_wrappers/source/rw_lock_posix.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 12 | |
| 13 | namespace webrtc { |
henrike@webrtc.org | 9f84723 | 2012-09-25 20:27:51 +0000 | [diff] [blame] | 14 | |
phoglund@webrtc.org | 59ad541 | 2012-12-18 15:20:35 +0000 | [diff] [blame] | 15 | RWLockPosix::RWLockPosix() : lock_() { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 16 | } |
| 17 | |
henrike@webrtc.org | 9f84723 | 2012-09-25 20:27:51 +0000 | [diff] [blame] | 18 | RWLockPosix::~RWLockPosix() { |
phoglund@webrtc.org | 59ad541 | 2012-12-18 15:20:35 +0000 | [diff] [blame] | 19 | pthread_rwlock_destroy(&lock_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 20 | } |
| 21 | |
henrike@webrtc.org | 9f84723 | 2012-09-25 20:27:51 +0000 | [diff] [blame] | 22 | RWLockPosix* RWLockPosix::Create() { |
| 23 | RWLockPosix* ret_val = new RWLockPosix(); |
| 24 | if (!ret_val->Init()) { |
| 25 | delete ret_val; |
| 26 | return NULL; |
| 27 | } |
| 28 | return ret_val; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 29 | } |
| 30 | |
henrike@webrtc.org | 9f84723 | 2012-09-25 20:27:51 +0000 | [diff] [blame] | 31 | bool RWLockPosix::Init() { |
phoglund@webrtc.org | 59ad541 | 2012-12-18 15:20:35 +0000 | [diff] [blame] | 32 | return pthread_rwlock_init(&lock_, 0) == 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 33 | } |
| 34 | |
henrike@webrtc.org | 9f84723 | 2012-09-25 20:27:51 +0000 | [diff] [blame] | 35 | void RWLockPosix::AcquireLockExclusive() { |
phoglund@webrtc.org | 59ad541 | 2012-12-18 15:20:35 +0000 | [diff] [blame] | 36 | pthread_rwlock_wrlock(&lock_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 37 | } |
| 38 | |
henrike@webrtc.org | 9f84723 | 2012-09-25 20:27:51 +0000 | [diff] [blame] | 39 | void RWLockPosix::ReleaseLockExclusive() { |
phoglund@webrtc.org | 59ad541 | 2012-12-18 15:20:35 +0000 | [diff] [blame] | 40 | pthread_rwlock_unlock(&lock_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 41 | } |
| 42 | |
henrike@webrtc.org | 9f84723 | 2012-09-25 20:27:51 +0000 | [diff] [blame] | 43 | void RWLockPosix::AcquireLockShared() { |
phoglund@webrtc.org | 59ad541 | 2012-12-18 15:20:35 +0000 | [diff] [blame] | 44 | pthread_rwlock_rdlock(&lock_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 45 | } |
henrike@webrtc.org | 9f84723 | 2012-09-25 20:27:51 +0000 | [diff] [blame] | 46 | |
| 47 | void RWLockPosix::ReleaseLockShared() { |
phoglund@webrtc.org | 59ad541 | 2012-12-18 15:20:35 +0000 | [diff] [blame] | 48 | pthread_rwlock_unlock(&lock_); |
henrike@webrtc.org | 9f84723 | 2012-09-25 20:27:51 +0000 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | } // namespace webrtc |