SCIRun  5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MutexPool.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 MutexPool
33 ///@brief A set of mutex objects
34 ///
35 ///@author Steve Parker
36 /// Department of Computer Science
37 /// University of Utah
38 ///@date September 1999
39 ///
40 
41 #ifndef Core_Thread_MutexPool_h
42 #define Core_Thread_MutexPool_h
43 
44 #include <vector>
45 #include <boost/shared_ptr.hpp>
48 
50 
51 namespace SCIRun {
52 /**************************************
53 
54 @class
55  MutexPool
56 
57 KEYWORDS
58  Thread, Mutex
59 
60 @details
61  A container class for a set of Mutex objects. This can be used to
62  limit the number of active mutexes down to a more reasonable set.
63  However, this must be used very carefully, as it becomes easy to
64  create a hold-and-wait condition.
65 ****************************************/
67  public:
68  //////////
69  /// Create the mutex pool with size mutex objects.
70  MutexPool(const char* name, int size);
71 
72  //////////
73  /// Destroy the mutex pool and all mutexes in it.
74  ~MutexPool();
75 
76 
77  //////////
78  /// return the next available mutex
79  Mutex &getMutex();
80 
81  private:
82  //////////
83  /// return the next index in a round-robin fashion
84  int nextIndex();
85 
86  //////////
87  /// The next ID
88  AtomicCounter nextID_;
89 
90  //////////
91  /// The number of Mutexes in the pool
92  int size_;
93 
94  //////////
95  /// The array of Mutex objects.
96  std::vector<boost::shared_ptr<Mutex> > pool_;
97 
98  //////////
99  /// Private copy ctor to prevent accidental copying
100  MutexPool(const MutexPool&);
101  //////////
102  /// Private assignment operator to prevent accidental assignment
103  MutexPool& operator=(const MutexPool&);
104  };
105 } // End namespace SCIRun
106 
107 #endif
108 
#define SCISHARE
Definition: share.h:39
Definition: Mutex.h:65
Definition: AtomicCounter.h:70
const char * name[]
Definition: BoostGraphExampleTests.cc:87
Definition: MutexPool.h:66
int size
Definition: eabLatVolData.py:2