blob: f21e0b043586a2f9c1af542d67f12f52dce111b1 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
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
henrike@webrtc.org9f847232012-09-25 20:27:51 +000011#include "system_wrappers/source/rw_lock_posix.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000012
13namespace webrtc {
henrike@webrtc.org9f847232012-09-25 20:27:51 +000014
15RWLockPosix::RWLockPosix() : _lock() {
niklase@google.com470e71d2011-07-07 08:21:25 +000016}
17
henrike@webrtc.org9f847232012-09-25 20:27:51 +000018RWLockPosix::~RWLockPosix() {
19 pthread_rwlock_destroy(&_lock);
niklase@google.com470e71d2011-07-07 08:21:25 +000020}
21
henrike@webrtc.org9f847232012-09-25 20:27:51 +000022RWLockPosix* 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.com470e71d2011-07-07 08:21:25 +000029}
30
henrike@webrtc.org9f847232012-09-25 20:27:51 +000031bool RWLockPosix::Init() {
32 return pthread_rwlock_init(&_lock, 0) == 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000033}
34
henrike@webrtc.org9f847232012-09-25 20:27:51 +000035void RWLockPosix::AcquireLockExclusive() {
36 pthread_rwlock_wrlock(&_lock);
niklase@google.com470e71d2011-07-07 08:21:25 +000037}
38
henrike@webrtc.org9f847232012-09-25 20:27:51 +000039void RWLockPosix::ReleaseLockExclusive() {
40 pthread_rwlock_unlock(&_lock);
niklase@google.com470e71d2011-07-07 08:21:25 +000041}
42
henrike@webrtc.org9f847232012-09-25 20:27:51 +000043void RWLockPosix::AcquireLockShared() {
44 pthread_rwlock_rdlock(&_lock);
niklase@google.com470e71d2011-07-07 08:21:25 +000045}
henrike@webrtc.org9f847232012-09-25 20:27:51 +000046
47void RWLockPosix::ReleaseLockShared() {
48 pthread_rwlock_unlock(&_lock);
49}
50
51} // namespace webrtc