]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/llvm/lib/Support/Unix/RWMutex.inc
MFV r355890:
[FreeBSD/FreeBSD.git] / contrib / llvm-project / llvm / lib / Support / Unix / RWMutex.inc
1 //= llvm/Support/Unix/RWMutex.inc - Unix Reader/Writer Mutual Exclusion Lock  =//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the Unix specific (non-pthread) RWMutex class.
10 //
11 //===----------------------------------------------------------------------===//
12
13 //===----------------------------------------------------------------------===//
14 //=== WARNING: Implementation here must contain only generic UNIX code that
15 //===          is guaranteed to work on *all* UNIX variants.
16 //===----------------------------------------------------------------------===//
17
18 #include "llvm/Support/Mutex.h"
19
20 namespace llvm {
21
22 using namespace sys;
23
24 // This naive implementation treats readers the same as writers.  This
25 // will therefore deadlock if a thread tries to acquire a read lock
26 // multiple times.
27
28 RWMutexImpl::RWMutexImpl() : data_(new MutexImpl(false)) { }
29
30 RWMutexImpl::~RWMutexImpl() {
31   delete static_cast<MutexImpl *>(data_);
32 }
33
34 bool RWMutexImpl::reader_acquire() {
35   return static_cast<MutexImpl *>(data_)->acquire();
36 }
37
38 bool RWMutexImpl::reader_release() {
39   return static_cast<MutexImpl *>(data_)->release();
40 }
41
42 bool RWMutexImpl::writer_acquire() {
43   return static_cast<MutexImpl *>(data_)->acquire();
44 }
45
46 bool RWMutexImpl::writer_release() {
47   return static_cast<MutexImpl *>(data_)->release();
48 }
49
50 }