LLVM API Documentation
00001 //===- llvm/System/Mutex.h - Mutex Operating System Concept -----*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file was developed by Reid Spencer and is distributed under the 00006 // University of Illinois Open Source License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file declares the llvm::sys::Mutex class. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef LLVM_SYSTEM_MUTEX_H 00015 #define LLVM_SYSTEM_MUTEX_H 00016 00017 namespace llvm 00018 { 00019 namespace sys 00020 { 00021 /// @brief Platform agnostic Mutex class. 00022 class Mutex 00023 { 00024 /// @name Constructors 00025 /// @{ 00026 public: 00027 00028 /// Initializes the lock but doesn't acquire it. if \p recursive is set 00029 /// to false, the lock will not be recursive which makes it cheaper but 00030 /// also more likely to deadlock (same thread can't acquire more than 00031 /// once). 00032 /// @brief Default Constructor. 00033 Mutex ( bool recursive = true ); 00034 00035 /// Releases and removes the lock 00036 /// @brief Destructor 00037 ~Mutex ( void ); 00038 00039 /// @} 00040 /// @name Methods 00041 /// @{ 00042 public: 00043 00044 /// Attempts to unconditionally acquire the lock. If the lock is held by 00045 /// another thread, this method will wait until it can acquire the lock. 00046 /// @returns false if any kind of error occurs, true otherwise. 00047 /// @brief Unconditionally acquire the lock. 00048 bool acquire(); 00049 00050 /// Attempts to release the lock. If the lock is held by the current 00051 /// thread, the lock is released allowing other threads to acquire the 00052 /// lock. 00053 /// @returns false if any kind of error occurs, true otherwise. 00054 /// @brief Unconditionally release the lock. 00055 bool release(void); 00056 00057 /// Attempts to acquire the lock without blocking. If the lock is not 00058 /// available, this function returns false quickly (without blocking). If 00059 /// the lock is available, it is acquired. 00060 /// @returns false if any kind of error occurs or the lock is not 00061 /// available, true otherwise. 00062 /// @brief Try to acquire the lock. 00063 bool tryacquire(); 00064 00065 //@} 00066 /// @name Platform Dependent Data 00067 /// @{ 00068 private: 00069 #ifdef ENABLE_THREADS 00070 void* data_; ///< We don't know what the data will be 00071 #endif 00072 00073 /// @} 00074 /// @name Do Not Implement 00075 /// @{ 00076 private: 00077 Mutex(const Mutex & original); 00078 void operator=(const Mutex &); 00079 /// @} 00080 }; 00081 } 00082 } 00083 00084 #endif