aboutsummaryrefslogtreecommitdiffstats
path: root/include/llvm/System
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2005-07-12 15:37:43 +0000
committerReid Spencer <rspencer@reidspencer.com>2005-07-12 15:37:43 +0000
commitb2164e5cb5086f0595e96fdbb5ffc614dea9c441 (patch)
tree1d75378c4ce6365fcaf202243766c4b400b809bd /include/llvm/System
parent22177fe580ef2e32cb2392408a00d8b6dfcaba6c (diff)
downloadexternal_llvm-b2164e5cb5086f0595e96fdbb5ffc614dea9c441.zip
external_llvm-b2164e5cb5086f0595e96fdbb5ffc614dea9c441.tar.gz
external_llvm-b2164e5cb5086f0595e96fdbb5ffc614dea9c441.tar.bz2
For PR540:
Add a Mutex class for thread synchronization in a platform-independent way. The current implementation only supports pthreads. Win32 use of Critical Sections will be added later. The design permits other threading models to be used if (and only if) pthreads is not available. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22403 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/System')
-rw-r--r--include/llvm/System/Mutex.h82
1 files changed, 82 insertions, 0 deletions
diff --git a/include/llvm/System/Mutex.h b/include/llvm/System/Mutex.h
new file mode 100644
index 0000000..16e898c
--- /dev/null
+++ b/include/llvm/System/Mutex.h
@@ -0,0 +1,82 @@
+//===- llvm/System/Mutex.h - Mutex Operating System Concept -----*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file was developed by Reid Spencer and is distributed under the
+// University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file declares the llvm::sys::Mutex class.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_SYSTEM_MUTEX_H
+#define LLVM_SYSTEM_MUTEX_H
+
+namespace llvm
+{
+ namespace sys
+ {
+ /// @brief Platform agnostic Mutex class.
+ class Mutex
+ {
+ /// @name Constructors
+ /// @{
+ public:
+
+ /// Initializes the lock but doesn't acquire it. if \p recursive is set
+ /// to false, the lock will not be recursive which makes it cheaper but
+ /// also more likely to deadlock (same thread can't acquire more than
+ /// once).
+ /// @brief Default Constructor.
+ Mutex ( bool recursive = true );
+
+ /// Releases and removes the lock
+ /// @brief Destructor
+ ~Mutex ( void );
+
+ /// @}
+ /// @name Methods
+ /// @{
+ public:
+
+ /// Attempts to unconditionally acquire the lock. If the lock is held by
+ /// another thread, 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.
+ bool acquire();
+
+ /// Attempts to release the lock. If the lock is held by the current
+ /// thread, the lock is released allowing other threads to acquire the
+ /// lock.
+ /// @returns false if any kind of error occurs, true otherwise.
+ /// @brief Unconditionally release the lock.
+ bool release(void);
+
+ /// Attempts to acquire the lock without blocking. If the lock is not
+ /// available, this function returns false quickly (without blocking). If
+ /// the lock is available, it is acquired.
+ /// @returns false if any kind of error occurs or the lock is not
+ /// available, true otherwise.
+ /// @brief Try to acquire the lock.
+ bool tryacquire();
+
+ //@}
+ /// @name Platform Dependent Data
+ /// @{
+ private:
+ void* data_; ///< We don't know what the data will be
+
+ /// @}
+ /// @name Do Not Implement
+ /// @{
+ private:
+ Mutex(const Mutex & original);
+ void operator=(const Mutex &);
+ /// @}
+ };
+ }
+}
+
+#endif