blob: 412873c770bf38043b885618ba8c81668911c6ac [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "system_wrappers/source/rw_lock_posix.h"
tommi@webrtc.orgfe196992015-02-07 22:35:54 +000012
13namespace webrtc {
14
Karl Wiberg79eb1d92017-11-08 12:26:07 +010015RWLockPosix::RWLockPosix() : lock_() {}
tommi@webrtc.orgfe196992015-02-07 22:35:54 +000016
17RWLockPosix::~RWLockPosix() {
18 pthread_rwlock_destroy(&lock_);
19}
20
21RWLockPosix* 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
30bool RWLockPosix::Init() {
31 return pthread_rwlock_init(&lock_, 0) == 0;
32}
33
34void RWLockPosix::AcquireLockExclusive() {
35 pthread_rwlock_wrlock(&lock_);
36}
37
38void RWLockPosix::ReleaseLockExclusive() {
39 pthread_rwlock_unlock(&lock_);
40}
41
42void RWLockPosix::AcquireLockShared() {
43 pthread_rwlock_rdlock(&lock_);
44}
45
46void RWLockPosix::ReleaseLockShared() {
47 pthread_rwlock_unlock(&lock_);
48}
49
50} // namespace webrtc