SCIRun
5.0
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
Core
Thread
Legacy
AtomicCounter.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 AtomicCounter.h
33
*@brief Thread-safe integer variable
34
*
35
* @author Steve Parker
36
* Department of Computer Science
37
* University of Utah
38
* @date June 1997
39
*
40
*/
41
42
#ifndef Core_Thread_AtomicCounter_h
43
#define Core_Thread_AtomicCounter_h
44
45
#include <
Core/Thread/Legacy/share.h
>
46
47
namespace
SCIRun {
48
49
class
AtomicCounter_private;
50
51
/**************************************
52
53
@class
54
AtomicCounter
55
56
KEYWORDS
57
Thread
58
59
@details
60
Provides a simple atomic counter. This will work just like an
61
integer, but guarantees atomicty of the ++ and -- operators.
62
Despite their convenience, you do not want to make a large number
63
of these objects. See also WorkQueue.
64
65
Not that this implementation does not offer an operator=, but
66
instead uses a "set" method. This is to avoid the inadvertant
67
use of a statement like: x=x+2, which would NOT be thread safe.
68
69
****************************************/
70
class
SCISHARE
AtomicCounter
{
71
public
:
72
//////////
73
/// Create an atomic counter with an unspecified initial value.
74
/// <tt>name</tt> should be a static string which describes the
75
/// primitive for debugging purposes.
76
AtomicCounter
(
const
char
*
name
);
77
78
//////////
79
/// Create an atomic counter with an initial value. name should
80
/// be a static string which describes the primitive for debugging
81
/// purposes.
82
AtomicCounter
(
const
char
* name,
int
value);
83
84
//////////
85
/// Destroy the atomic counter.
86
~
AtomicCounter
();
87
88
//////////
89
/// Allows the atomic counter to be used in expressions like
90
/// a normal integer. Note that multiple calls to this function
91
/// may return different values if other threads are manipulating
92
/// the counter.
93
operator
int()
const
;
94
95
//////////
96
/// Increment the counter and return the new value.
97
/// This does not return AtomicCounter& like a normal ++
98
/// operator would, because it would destroy atomicity
99
int
operator++();
100
101
//////////
102
/// Increment the counter and return the old value
103
int
operator++(
int
);
104
105
//////////
106
/// Decrement the counter and return the new value
107
/// This does not return AtomicCounter& like a normal --
108
/// operator would, because it would destroy atomicity
109
int
operator--();
110
111
//////////
112
/// Decrement the counter and return the old value
113
int
operator--(
int
);
114
115
//////////
116
/// Set the counter to a new value
117
void
set(
int
);
118
119
private
:
120
const
char
* name_;
121
AtomicCounter_private
* priv_;
122
123
// Cannot copy them
124
AtomicCounter
(
const
AtomicCounter
&);
125
AtomicCounter
& operator=(
const
AtomicCounter
&);
126
};
127
}
// End namespace SCIRun
128
129
#endif
130
SCIRun::AtomicCounter_private
Definition:
Thread_none.cc:399
share.h
SCISHARE
#define SCISHARE
Definition:
share.h:39
SCIRun::AtomicCounter
Definition:
AtomicCounter.h:70
name
const char * name[]
Definition:
BoostGraphExampleTests.cc:87
Generated on Wed Jul 9 2014 14:31:48 for SCIRun by
1.8.5