1 //= llvm/Support/Unix/RWMutex.inc - Unix Reader/Writer Mutual Exclusion Lock =//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file implements the Unix specific (non-pthread) RWMutex class.
11 //===----------------------------------------------------------------------===//
13 //===----------------------------------------------------------------------===//
14 //=== WARNING: Implementation here must contain only generic UNIX code that
15 //=== is guaranteed to work on *all* UNIX variants.
16 //===----------------------------------------------------------------------===//
18 #include "llvm/Support/Mutex.h"
24 // This naive implementation treats readers the same as writers. This
25 // will therefore deadlock if a thread tries to acquire a read lock
28 RWMutexImpl::RWMutexImpl() : data_(new MutexImpl(false)) { }
30 RWMutexImpl::~RWMutexImpl() {
31 delete static_cast<MutexImpl *>(data_);
34 bool RWMutexImpl::reader_acquire() {
35 return static_cast<MutexImpl *>(data_)->acquire();
38 bool RWMutexImpl::reader_release() {
39 return static_cast<MutexImpl *>(data_)->release();
42 bool RWMutexImpl::writer_acquire() {
43 return static_cast<MutexImpl *>(data_)->acquire();
46 bool RWMutexImpl::writer_release() {
47 return static_cast<MutexImpl *>(data_)->release();