SCIRun  5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Mutex.h
Go to the documentation of this file.
1 /*
2  For more information, please see: http://software.sci.utah.edu
3 
4  The MIT License
5 
6  Copyright (c) 2009 Scientific Computing and Imaging Institute,
7  University of Utah.
8 
9 
10  Permission is hereby granted, free of charge, to any person obtaining a
11  copy of this software and associated documentation files (the "Software"),
12  to deal in the Software without restriction, including without limitation
13  the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  and/or sell copies of the Software, and to permit persons to whom the
15  Software is furnished to do so, subject to the following conditions:
16 
17  The above copyright notice and this permission notice shall be included
18  in all copies or substantial portions of the Software.
19 
20  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26  DEALINGS IN THE SOFTWARE.
27 */
28 
29 
30 
31 ///
32 ///@file Mutex.h
33 ///@brief Standard locking primitive
34 ///
35 ///@author Steve Parker
36 /// Department of Computer Science
37 /// University of Utah
38 ///@date June 1997
39 ///
40 
41 #ifndef Core_Thread_Mutex_h
42 #define Core_Thread_Mutex_h
43 
45 
46 namespace SCIRun {
47 
48 struct Mutex_private;
49 
50 /**************************************
51 
52 @class
53  Mutex
54 
55  KEYWORDS
56  Thread
57 
58 @details
59  Provides a simple <b>Mut</b>ual <b>Ex</b>clusion primitive. Atomic
60  <b>lock()</b> and <b>unlock()</b> will lock and unlock the mutex.
61  This is not a recursive Mutex (See <b>RecursiveMutex</b>), and calling
62  lock() in a nested call will result in an error or deadlock.
63 
64 ****************************************/
65 class SCISHARE Mutex {
66 public:
67  //////////
68  /// Create the mutex. The mutex is allocated in the unlocked
69  /// state. <i>name</i> should be a static string which describes
70  /// the primitive for debugging purposes.
71  explicit Mutex(const char* name);
72 
73  //////////
74  /// Destroy the mutex. Destroying the mutex in the locked state
75  /// has undefined results.
76  ~Mutex();
77 
78  //////////
79  /// Acquire the Mutex. This method will block until the mutex
80  /// is acquired.
81  void lock();
82 
83  //////////
84  /// Attempt to acquire the Mutex without blocking. Returns
85  /// true if the mutex was available and actually acquired.
86  bool tryLock();
87 
88  //////////
89  /// Release the Mutex, unblocking any other threads that are
90  /// blocked waiting for the Mutex.
91  void unlock();
92  friend class ConditionVariable;
93 private:
94  Mutex_private* priv_;
95  const char* name_;
96 
97  // Cannot copy them
98  Mutex(const Mutex&);
99  Mutex& operator=(const Mutex&);
100 };
101 
102 } // End namespace SCIRun
103 
104 #endif
105 
106 
#define SCISHARE
Definition: share.h:39
Definition: ConditionVariable.h:80
Definition: Thread_pthreads.cc:788
Definition: Mutex.h:65
const char * name[]
Definition: BoostGraphExampleTests.cc:87
boost::mutex Mutex
Definition: SchedulingWithBoostGraph.cc:434