1 //===- RWMutex.h - Reader/Writer Mutual Exclusion Lock ----------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares the llvm::sys::RWMutex class.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_SYSTEM_RWMUTEX_H
15 #define LLVM_SYSTEM_RWMUTEX_H
21 /// @brief Platform agnostic Mutex class.
24 /// @name Constructors
28 /// Initializes the lock but doesn't acquire it.
29 /// @brief Default Constructor.
32 /// Releases and removes the lock
41 /// Attempts to unconditionally acquire the lock in reader mode. If the
42 /// lock is held by a writer, this method will wait until it can acquire
44 /// @returns false if any kind of error occurs, true otherwise.
45 /// @brief Unconditionally acquire the lock in reader mode.
46 bool reader_acquire();
48 /// Attempts to release the lock in reader mode.
49 /// @returns false if any kind of error occurs, true otherwise.
50 /// @brief Unconditionally release the lock in reader mode.
51 bool reader_release();
53 /// Attempts to unconditionally acquire the lock in reader mode. If the
54 /// lock is held by any readers, this method will wait until it can
56 /// @returns false if any kind of error occurs, true otherwise.
57 /// @brief Unconditionally acquire the lock in writer mode.
58 bool writer_acquire();
60 /// Attempts to release the lock in writer mode.
61 /// @returns false if any kind of error occurs, true otherwise.
62 /// @brief Unconditionally release the lock in write mode.
63 bool writer_release();
66 /// @name Platform Dependent Data
70 void* data_; ///< We don't know what the data will be
74 /// @name Do Not Implement
77 RWMutex(const RWMutex & original);
78 void operator=(const RWMutex &);
82 /// ScopedReader - RAII acquisition of a reader lock
86 explicit ScopedReader(RWMutex* m) {
88 mutex->reader_acquire();
92 mutex->reader_release();
96 /// ScopedWriter - RAII acquisition of a writer lock
100 explicit ScopedWriter(RWMutex* m) {
102 mutex->writer_acquire();
106 mutex->writer_release();