SCIRun  5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Semaphore.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 Semaphore
33 ///@breif Basic semaphore 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_Semaphore_h
42 #define Core_Thread_Semaphore_h
43 
45 
46 namespace SCIRun {
47 
48 class Semaphore_private;
49 
50 /**************************************
51 
52 @class
53  Semaphore
54 
55  KEYWORDS
56  Thread
57 
58 @detials
59  Counting semaphore synchronization primitive. A semaphore provides
60  atomic access to a special counter. The <i>up</i> method is used
61  to increment the counter, and the <i>down</i> method is used to
62  decrement the counter. If a thread tries to decrement the counter
63  when the counter is zero, that thread will be blocked until another
64  thread calls the <i>up</i> method.
65 
66 ****************************************/
68 public:
69  //////////
70  /// Create the semaphore, and setup the initial <i>count.name</i>
71  /// should be a static string which describes the primitive for
72  /// debugging purposes.
73  Semaphore(const char* name, int count);
74 
75  //////////
76  /// Destroy the semaphore
77  ~Semaphore();
78 
79  //////////
80  /// Increment the semaphore count, unblocking up to <i>count</i>
81  /// threads that may be blocked in the <i>down</i> method.
82  void up(int count=1);
83 
84  //////////
85  /// Decrement the semaphore count by <i>count</i>. If the
86  /// count is zero, this thread will be blocked until another
87  /// thread calls the <i>up</i> method. The order in which
88  /// threads will be unblocked is not defined, but implementors
89  /// should give preference to those threads that have waited
90  /// the longest.
91  void down(int count=1);
92 
93  //////////
94  /// Attempt to decrement the semaphore count by one, but will
95  /// never block. If the count was zero, <i>tryDown</i> will
96  /// return false. Otherwise, <i>tryDown</i> will return true.
97  bool tryDown();
98 
99 private:
100  Semaphore_private* priv_;
101  const char* name_;
102 
103  // Cannot copy them
104  Semaphore(const Semaphore&);
105  Semaphore& operator=(const Semaphore&);
106 };
107 } // End namespace SCIRun
108 
109 #endif
110 
#define SCISHARE
Definition: share.h:39
Definition: Thread_pthreads.cc:1125
const char * name[]
Definition: BoostGraphExampleTests.cc:87
Definition: Semaphore.h:67
int count
Definition: readAllFields.py:25