Home | History | Annotate | Download | only in synchronization
      1 // Copyright 2016 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "base/synchronization/read_write_lock.h"
      6 
      7 #include "base/logging.h"
      8 
      9 namespace base {
     10 namespace subtle {
     11 
     12 ReadWriteLock::ReadWriteLock() : native_handle_(PTHREAD_RWLOCK_INITIALIZER) {}
     13 
     14 ReadWriteLock::~ReadWriteLock() {
     15   int result = pthread_rwlock_destroy(&native_handle_);
     16   DCHECK_EQ(result, 0) << ". " << strerror(result);
     17 }
     18 
     19 void ReadWriteLock::ReadAcquire() {
     20   int result = pthread_rwlock_rdlock(&native_handle_);
     21   DCHECK_EQ(result, 0) << ". " << strerror(result);
     22 }
     23 
     24 void ReadWriteLock::ReadRelease() {
     25   int result = pthread_rwlock_unlock(&native_handle_);
     26   DCHECK_EQ(result, 0) << ". " << strerror(result);
     27 }
     28 
     29 void ReadWriteLock::WriteAcquire() {
     30   int result = pthread_rwlock_wrlock(&native_handle_);
     31   DCHECK_EQ(result, 0) << ". " << strerror(result);
     32 }
     33 
     34 void ReadWriteLock::WriteRelease() {
     35   int result = pthread_rwlock_unlock(&native_handle_);
     36   DCHECK_EQ(result, 0) << ". " << strerror(result);
     37 }
     38 
     39 }  // namespace subtle
     40 }  // namespace base
     41