LLVM  10.0.0svn
RWMutex.inc
Go to the documentation of this file.
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 
31  delete static_cast<MutexImpl *>(data_);
32 }
33 
35  return static_cast<MutexImpl *>(data_)->acquire();
36 }
37 
39  return static_cast<MutexImpl *>(data_)->release();
40 }
41 
43  return static_cast<MutexImpl *>(data_)->acquire();
44 }
45 
47  return static_cast<MutexImpl *>(data_)->release();
48 }
49 
50 }
This class represents lattice values for constants.
Definition: AllocatorList.h:23
bool reader_release()
Attempts to release the lock in reader mode.
Definition: RWMutex.cpp:88
bool writer_acquire()
Attempts to unconditionally acquire the lock in reader mode.
Definition: RWMutex.cpp:98
bool reader_acquire()
Attempts to unconditionally acquire the lock in reader mode.
Definition: RWMutex.cpp:78
RWMutexImpl()
Initializes the lock but doesn&#39;t acquire it.
Definition: RWMutex.cpp:48
bool writer_release()
Attempts to release the lock in writer mode.
Definition: RWMutex.cpp:108
~RWMutexImpl()
Releases and removes the lock Destructor.
Definition: RWMutex.cpp:69