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 | |
Karl Wiberg | 2b85792 | 2018-03-23 14:53:54 +0100 | [diff] [blame] | 11 | #include "rtc_base/synchronization/rw_lock_posix.h" |
tommi@webrtc.org | fe19699 | 2015-02-07 22:35:54 +0000 | [diff] [blame] | 12 | |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 13 | #include <stddef.h> |
| 14 | |
tommi@webrtc.org | fe19699 | 2015-02-07 22:35:54 +0000 | [diff] [blame] | 15 | namespace webrtc { |
| 16 | |
Karl Wiberg | 79eb1d9 | 2017-11-08 12:26:07 +0100 | [diff] [blame] | 17 | RWLockPosix::RWLockPosix() : lock_() {} |
tommi@webrtc.org | fe19699 | 2015-02-07 22:35:54 +0000 | [diff] [blame] | 18 | |
| 19 | RWLockPosix::~RWLockPosix() { |
| 20 | pthread_rwlock_destroy(&lock_); |
| 21 | } |
| 22 | |
| 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 | |
| 32 | bool RWLockPosix::Init() { |
| 33 | return pthread_rwlock_init(&lock_, 0) == 0; |
| 34 | } |
| 35 | |
| 36 | void RWLockPosix::AcquireLockExclusive() { |
| 37 | pthread_rwlock_wrlock(&lock_); |
| 38 | } |
| 39 | |
| 40 | void RWLockPosix::ReleaseLockExclusive() { |
| 41 | pthread_rwlock_unlock(&lock_); |
| 42 | } |
| 43 | |
| 44 | void RWLockPosix::AcquireLockShared() { |
| 45 | pthread_rwlock_rdlock(&lock_); |
| 46 | } |
| 47 | |
| 48 | void RWLockPosix::ReleaseLockShared() { |
| 49 | pthread_rwlock_unlock(&lock_); |
| 50 | } |
| 51 | |
| 52 | } // namespace webrtc |