summaryrefslogtreecommitdiff
path: root/include/llvm/System
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2009-06-16 20:19:28 +0000
committerOwen Anderson <resistor@mac.com>2009-06-16 20:19:28 +0000
commit2a8cf9aadd39e507e6e09c25530a2f01ca27fe57 (patch)
tree2d21b27491e24b1fcd0f8510e0e9ccaff40c1ea4 /include/llvm/System
parent1555a23335400143f2b54a66aedc4b5cbbb79f8d (diff)
downloadllvm-2a8cf9aadd39e507e6e09c25530a2f01ca27fe57.tar.gz
llvm-2a8cf9aadd39e507e6e09c25530a2f01ca27fe57.tar.bz2
llvm-2a8cf9aadd39e507e6e09c25530a2f01ca27fe57.tar.xz
Add a portable wrapper for reader-writer locks.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@73545 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/System')
-rw-r--r--include/llvm/System/RWMutex.h84
1 files changed, 84 insertions, 0 deletions
diff --git a/include/llvm/System/RWMutex.h b/include/llvm/System/RWMutex.h
new file mode 100644
index 0000000000..eb56eec75f
--- /dev/null
+++ b/include/llvm/System/RWMutex.h
@@ -0,0 +1,84 @@
+//===- RWMutex.h - Reader/Writer Mutual Exclusion Lock ----------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file declares the llvm::sys::RWMutex class.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_SYSTEM_MUTEX_H
+#define LLVM_SYSTEM_MUTEX_H
+
+namespace llvm
+{
+ namespace sys
+ {
+ /// @brief Platform agnostic Mutex class.
+ class RWMutex
+ {
+ /// @name Constructors
+ /// @{
+ public:
+
+ /// Initializes the lock but doesn't acquire it.
+ /// @brief Default Constructor.
+ explicit RWMutex();
+
+ /// Releases and removes the lock
+ /// @brief Destructor
+ ~RWMutex();
+
+ /// @}
+ /// @name Methods
+ /// @{
+ public:
+
+ /// Attempts to unconditionally acquire the lock in reader mode. If the
+ /// lock is held by a writer, this method will wait until it can acquire
+ /// the lock.
+ /// @returns false if any kind of error occurs, true otherwise.
+ /// @brief Unconditionally acquire the lock in reader mode.
+ bool reader_acquire();
+
+ /// Attempts to release the lock in reader mode.
+ /// @returns false if any kind of error occurs, true otherwise.
+ /// @brief Unconditionally release the lock in reader mode.
+ bool reader_release();
+
+ /// Attempts to unconditionally acquire the lock in reader mode. If the
+ /// lock is held by any readers, this method will wait until it can
+ /// acquire the lock.
+ /// @returns false if any kind of error occurs, true otherwise.
+ /// @brief Unconditionally acquire the lock in writer mode.
+ bool writer_acquire();
+
+ /// Attempts to release the lock in writer mode.
+ /// @returns false if any kind of error occurs, true otherwise.
+ /// @brief Unconditionally release the lock in write mode.
+ bool writer_release();
+
+ //@}
+ /// @name Platform Dependent Data
+ /// @{
+ private:
+#ifdef ENABLE_THREADS
+ void* data_; ///< We don't know what the data will be
+#endif
+
+ /// @}
+ /// @name Do Not Implement
+ /// @{
+ private:
+ RWMutex(const RWMutex & original);
+ void operator=(const RWMutex &);
+ /// @}
+ };
+ }
+}
+
+#endif