Untabify.
[oota-llvm.git] / include / llvm / System / Mutex.h
1 //===- llvm/System/Mutex.h - Mutex Operating System Concept -----*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares the llvm::sys::Mutex class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_SYSTEM_MUTEX_H
15 #define LLVM_SYSTEM_MUTEX_H
16
17 namespace llvm
18 {
19   namespace sys
20   {
21     /// @brief Platform agnostic Mutex class.
22     class Mutex
23     {
24     /// @name Constructors
25     /// @{
26     public:
27
28       /// Initializes the lock but doesn't acquire it. if \p recursive is set
29       /// to false, the lock will not be recursive which makes it cheaper but
30       /// also more likely to deadlock (same thread can't acquire more than
31       /// once).
32       /// @brief Default Constructor.
33       explicit Mutex(bool recursive = true);
34
35       /// Releases and removes the lock
36       /// @brief Destructor
37       ~Mutex();
38
39     /// @}
40     /// @name Methods
41     /// @{
42     public:
43
44       /// Attempts to unconditionally acquire the lock. If the lock is held by
45       /// another thread, this method will wait until it can acquire the lock.
46       /// @returns false if any kind of error occurs, true otherwise.
47       /// @brief Unconditionally acquire the lock.
48       bool acquire();
49
50       /// Attempts to release the lock. If the lock is held by the current
51       /// thread, the lock is released allowing other threads to acquire the
52       /// lock.
53       /// @returns false if any kind of error occurs, true otherwise.
54       /// @brief Unconditionally release the lock.
55       bool release();
56
57       /// Attempts to acquire the lock without blocking. If the lock is not
58       /// available, this function returns false quickly (without blocking). If
59       /// the lock is available, it is acquired.
60       /// @returns false if any kind of error occurs or the lock is not
61       /// available, true otherwise.
62       /// @brief Try to acquire the lock.
63       bool tryacquire();
64
65     //@}
66     /// @name Platform Dependent Data
67     /// @{
68     private:
69 #ifdef ENABLE_THREADS
70       void* data_; ///< We don't know what the data will be
71 #endif
72
73     /// @}
74     /// @name Do Not Implement
75     /// @{
76     private:
77       Mutex(const Mutex & original);
78       void operator=(const Mutex &);
79     /// @}
80     };
81   }
82 }
83
84 #endif