Blaze 3.9
SerialSection.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_MATH_SMP_SERIALSECTION_H_
36#define _BLAZE_MATH_SMP_SERIALSECTION_H_
37
38
39//*************************************************************************************************
40// Includes
41//*************************************************************************************************
42
44#include <blaze/util/Suffix.h>
45
46
47namespace blaze {
48
49//=================================================================================================
50//
51// CLASS DEFINITION
52//
53//=================================================================================================
54
55//*************************************************************************************************
63template< typename T >
65{
66 public:
67 //**Constructor*********************************************************************************
70 inline SerialSection( bool activate );
72 //**********************************************************************************************
73
74 //**Destructor**********************************************************************************
77 inline ~SerialSection();
79 //**********************************************************************************************
80
81 //**Conversion operator*************************************************************************
84 inline operator bool() const;
86 //**********************************************************************************************
87
88 private:
89 //**Member variables****************************************************************************
92 static bool active_;
97 //**********************************************************************************************
98
99 //**Friend declarations*************************************************************************
101 friend bool isSerialSectionActive();
103 //**********************************************************************************************
104};
105//*************************************************************************************************
106
107
108
109
110//=================================================================================================
111//
112// DEFINITION AND INITIALIZATION OF THE STATIC MEMBER VARIABLES
113//
114//=================================================================================================
115
116//*************************************************************************************************
118template< typename T >
119bool SerialSection<T>::active_ = false;
121//*************************************************************************************************
122
123
124
125
126//=================================================================================================
127//
128// CONSTRUCTOR
129//
130//=================================================================================================
131
132//*************************************************************************************************
138template< typename T >
139inline SerialSection<T>::SerialSection( bool activate )
140{
141 if( active_ ) {
142 BLAZE_THROW_RUNTIME_ERROR( "Nested serial sections detected" );
143 }
144
145 active_ = activate;
146}
147//*************************************************************************************************
148
149
150
151
152//=================================================================================================
153//
154// DESTRUCTOR
155//
156//=================================================================================================
157
158//*************************************************************************************************
161template< typename T >
163{
164 active_ = false; // Resetting the activity flag
165}
166//*************************************************************************************************
167
168
169
170
171//=================================================================================================
172//
173// CONVERSION OPERATOR
174//
175//=================================================================================================
176
177//*************************************************************************************************
183template< typename T >
184inline SerialSection<T>::operator bool() const
185{
186 return active_;
187}
188//*************************************************************************************************
189
190
191
192
193//=================================================================================================
194//
195// GLOBAL FUNCTIONS
196//
197//=================================================================================================
198
199//*************************************************************************************************
202inline bool isSerialSectionActive();
204//*************************************************************************************************
205
206
207//*************************************************************************************************
214{
216}
217//*************************************************************************************************
218
219
220
221
222
223
224
225
226//=================================================================================================
227//
228// SERIAL SECTION MACRO
229//
230//=================================================================================================
231
232//*************************************************************************************************
262#define BLAZE_SERIAL_SECTION \
263 if( blaze::SerialSection<int> BLAZE_JOIN( serialSection, __LINE__ ) = true )
264//*************************************************************************************************
265
266} // namespace blaze
267
268#endif
Header file for compile time constraints.
Section to enforce the serial execution of operations.
Definition: SerialSection.h:65
static bool active_
Activity flag for the serial section.
Definition: SerialSection.h:92
SerialSection(bool activate)
Constructor for the SerialSection class.
Definition: SerialSection.h:139
~SerialSection()
Destructor of the SerialSection class.
Definition: SerialSection.h:162
bool isSerialSectionActive()
Returns whether a serial section is active or not.
Definition: SerialSection.h:213
#define BLAZE_THROW_RUNTIME_ERROR(MESSAGE)
Macro for the emission of a std::runtime_error exception.
Definition: Exception.h:379
Header file for the exception macros of the math module.