LLVM API Documentation

Mutex.h

Go to the documentation of this file.
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 #include "llvm/System/IncludeFile.h"
00018 
00019 namespace llvm
00020 {
00021   namespace sys
00022   {
00023     /// @brief Platform agnostic Mutex class.
00024     class Mutex
00025     {
00026     /// @name Constructors
00027     /// @{
00028     public:
00029 
00030       /// Initializes the lock but doesn't acquire it. if \p recursive is set
00031       /// to false, the lock will not be recursive which makes it cheaper but
00032       /// also more likely to deadlock (same thread can't acquire more than
00033       /// once).
00034       /// @brief Default Constructor.
00035       Mutex ( bool recursive = true );
00036 
00037       /// Releases and removes the lock
00038       /// @brief Destructor
00039       ~Mutex ( void );
00040 
00041     /// @}
00042     /// @name Methods
00043     /// @{
00044     public:
00045 
00046       /// Attempts to unconditionally acquire the lock. If the lock is held by
00047       /// another thread, this method will wait until it can acquire the lock.
00048       /// @returns false if any kind of error occurs, true otherwise.
00049       /// @brief Unconditionally acquire the lock.
00050       bool acquire();
00051 
00052       /// Attempts to release the lock. If the lock is held by the current
00053       /// thread, the lock is released allowing other threads to acquire the
00054       /// lock.
00055       /// @returns false if any kind of error occurs, true otherwise.
00056       /// @brief Unconditionally release the lock.
00057       bool release(void);
00058 
00059       /// Attempts to acquire the lock without blocking. If the lock is not
00060       /// available, this function returns false quickly (without blocking). If
00061       /// the lock is available, it is acquired.
00062       /// @returns false if any kind of error occurs or the lock is not
00063       /// available, true otherwise.
00064       /// @brief Try to acquire the lock.
00065       bool tryacquire();
00066 
00067     //@}
00068     /// @name Platform Dependent Data
00069     /// @{
00070     private:
00071 #ifdef ENABLE_THREADS
00072       void* data_; ///< We don't know what the data will be
00073 #endif
00074 
00075     /// @}
00076     /// @name Do Not Implement
00077     /// @{
00078     private:
00079       Mutex(const Mutex & original);
00080       void operator=(const Mutex &);
00081     /// @}
00082     };
00083   }
00084 }
00085 
00086 FORCE_DEFINING_FILE_TO_BE_LINKED(SystemMutex)
00087 
00088 #endif