tommi@webrtc.org | fe19699 | 2015-02-07 22:35:54 +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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "system_wrappers/source/rw_lock_posix.h" |
tommi@webrtc.org | fe19699 | 2015-02-07 22:35:54 +0000 | [diff] [blame] | 12 | |
| 13 | namespace webrtc { |
| 14 | |
Karl Wiberg | 79eb1d9 | 2017-11-08 12:26:07 +0100 | [diff] [blame] | 15 | RWLockPosix::RWLockPosix() : lock_() {} |
tommi@webrtc.org | fe19699 | 2015-02-07 22:35:54 +0000 | [diff] [blame] | 16 | |
| 17 | RWLockPosix::~RWLockPosix() { |
| 18 | pthread_rwlock_destroy(&lock_); |
| 19 | } |
| 20 | |
| 21 | RWLockPosix* RWLockPosix::Create() { |
| 22 | RWLockPosix* ret_val = new RWLockPosix(); |
| 23 | if (!ret_val->Init()) { |
| 24 | delete ret_val; |
| 25 | return NULL; |
| 26 | } |
| 27 | return ret_val; |
| 28 | } |
| 29 | |
| 30 | bool RWLockPosix::Init() { |
| 31 | return pthread_rwlock_init(&lock_, 0) == 0; |
| 32 | } |
| 33 | |
| 34 | void RWLockPosix::AcquireLockExclusive() { |
| 35 | pthread_rwlock_wrlock(&lock_); |
| 36 | } |
| 37 | |
| 38 | void RWLockPosix::ReleaseLockExclusive() { |
| 39 | pthread_rwlock_unlock(&lock_); |
| 40 | } |
| 41 | |
| 42 | void RWLockPosix::AcquireLockShared() { |
| 43 | pthread_rwlock_rdlock(&lock_); |
| 44 | } |
| 45 | |
| 46 | void RWLockPosix::ReleaseLockShared() { |
| 47 | pthread_rwlock_unlock(&lock_); |
| 48 | } |
| 49 | |
| 50 | } // namespace webrtc |