SCIRun  5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Lockable.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 /// @todo Documentation Core/Utils/Lockable.h
29 
30 #ifndef CORE_UTILS_LOCKABLE_H
31 #define CORE_UTILS_LOCKABLE_H
32 
33 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
34 # pragma once
35 #endif
36 
37 #include <boost/thread/mutex.hpp>
38 #include <boost/thread/recursive_mutex.hpp>
39 #include <boost/thread/shared_mutex.hpp>
40 #include <boost/noncopyable.hpp>
41 
42 namespace SCIRun
43 {
44 namespace Core
45 {
46 
47 class Lockable : boost::noncopyable
48 {
49 public:
50  typedef boost::mutex mutex_type;
51  typedef boost::unique_lock< mutex_type > lock_type;
52 
53  Lockable() {}
54  ~Lockable() {}
55 
57  {
58  return this->mutex_;
59  }
60 
61 private:
62  mutable mutex_type mutex_;
63 };
64 
65 class RecursiveLockable : boost::noncopyable
66 {
67 public:
68  typedef boost::recursive_mutex mutex_type;
69  typedef boost::unique_lock< mutex_type > lock_type;
70 
73 
75  {
76  return this->mutex_;
77  }
78 
79 private:
80  mutable mutex_type mutex_;
81 };
82 
83 class SharedLockable : boost::noncopyable
84 {
85 public:
86  typedef boost::shared_mutex mutex_type;
87  typedef boost::unique_lock< mutex_type > lock_type;
88  typedef boost::shared_lock< mutex_type > shared_lock_type;
89  typedef boost::upgrade_lock< mutex_type > upgrade_lock_type;
90  typedef boost::upgrade_to_unique_lock< mutex_type > upgrade_to_unique_lock_type;
91 
94 
96  {
97  return this->mutex_;
98  }
99 
100 private:
101  mutable mutex_type mutex_;
102 };
103 
104 }}
105 
106 #endif
boost::unique_lock< mutex_type > lock_type
Definition: Lockable.h:69
~Lockable()
Definition: Lockable.h:54
boost::recursive_mutex mutex_type
Definition: Lockable.h:68
mutex_type & get_mutex() const
Definition: Lockable.h:95
boost::shared_lock< mutex_type > shared_lock_type
Definition: Lockable.h:88
boost::upgrade_to_unique_lock< mutex_type > upgrade_to_unique_lock_type
Definition: Lockable.h:90
Definition: Lockable.h:65
Definition: Lockable.h:47
mutex_type & get_mutex() const
Definition: Lockable.h:74
boost::unique_lock< mutex_type > lock_type
Definition: Lockable.h:87
RecursiveLockable()
Definition: Lockable.h:71
Lockable()
Definition: Lockable.h:53
Definition: Lockable.h:83
SharedLockable()
Definition: Lockable.h:92
~SharedLockable()
Definition: Lockable.h:93
~RecursiveLockable()
Definition: Lockable.h:72
boost::shared_mutex mutex_type
Definition: Lockable.h:86
boost::unique_lock< mutex_type > lock_type
Definition: Lockable.h:51
mutex_type & get_mutex() const
Definition: Lockable.h:56
boost::mutex mutex_type
Definition: Lockable.h:50
boost::upgrade_lock< mutex_type > upgrade_lock_type
Definition: Lockable.h:89