blob: 15ef3d706e8aecadddbccfed6118eea30bdf4c0b [file] [log] [blame]
tommi@webrtc.orgfe196992015-02-07 22:35:54 +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
Karl Wiberg2b857922018-03-23 14:53:54 +010011#include "rtc_base/synchronization/rw_lock_posix.h"
tommi@webrtc.orgfe196992015-02-07 22:35:54 +000012
Yves Gerey988cc082018-10-23 12:03:01 +020013#include <stddef.h>
14
tommi@webrtc.orgfe196992015-02-07 22:35:54 +000015namespace webrtc {
16
Karl Wiberg79eb1d92017-11-08 12:26:07 +010017RWLockPosix::RWLockPosix() : lock_() {}
tommi@webrtc.orgfe196992015-02-07 22:35:54 +000018
19RWLockPosix::~RWLockPosix() {
20 pthread_rwlock_destroy(&lock_);
21}
22
23RWLockPosix* 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
32bool RWLockPosix::Init() {
33 return pthread_rwlock_init(&lock_, 0) == 0;
34}
35
36void RWLockPosix::AcquireLockExclusive() {
37 pthread_rwlock_wrlock(&lock_);
38}
39
40void RWLockPosix::ReleaseLockExclusive() {
41 pthread_rwlock_unlock(&lock_);
42}
43
44void RWLockPosix::AcquireLockShared() {
45 pthread_rwlock_rdlock(&lock_);
46}
47
48void RWLockPosix::ReleaseLockShared() {
49 pthread_rwlock_unlock(&lock_);
50}
51
52} // namespace webrtc