All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
43 #include <stdexcept>
44 
45 
46 namespace blaze {
47 
48 //=================================================================================================
49 //
50 // CLASS DEFINITION
51 //
52 //=================================================================================================
53 
54 //*************************************************************************************************
62 template< typename T >
64 {
65  public:
66  //**Constructor*********************************************************************************
69  inline SerialSection( bool activate );
71  //**********************************************************************************************
72 
73  //**Destructor**********************************************************************************
76  inline ~SerialSection();
78  //**********************************************************************************************
79 
80  //**Conversion operator*************************************************************************
83  inline operator bool() const;
85  //**********************************************************************************************
86 
87  private:
88  //**Member variables****************************************************************************
91  static bool active_;
92 
96  //**********************************************************************************************
97 
98  //**Friend declarations*************************************************************************
100  friend bool isSerialSectionActive();
102  //**********************************************************************************************
103 };
104 //*************************************************************************************************
105 
106 
107 
108 
109 //=================================================================================================
110 //
111 // DEFINITION AND INITIALIZATION OF THE STATIC MEMBER VARIABLES
112 //
113 //=================================================================================================
114 
115 //*************************************************************************************************
117 template< typename T >
118 bool SerialSection<T>::active_ = false;
120 //*************************************************************************************************
121 
122 
123 
124 
125 //=================================================================================================
126 //
127 // CONSTRUCTOR
128 //
129 //=================================================================================================
130 
131 //*************************************************************************************************
137 template< typename T >
138 inline SerialSection<T>::SerialSection( bool activate )
139 {
140  if( active_ )
141  throw std::runtime_error( "Nested serial sections detected" );
142 
143  active_ = activate;
144 }
145 //*************************************************************************************************
146 
147 
148 
149 
150 //=================================================================================================
151 //
152 // DESTRUCTOR
153 //
154 //=================================================================================================
155 
156 //*************************************************************************************************
159 template< typename T >
161 {
162  active_ = false; // Resetting the activity flag
163 }
164 //*************************************************************************************************
165 
166 
167 
168 
169 //=================================================================================================
170 //
171 // CONVERSION OPERATOR
172 //
173 //=================================================================================================
174 
175 //*************************************************************************************************
181 template< typename T >
182 inline SerialSection<T>::operator bool() const
183 {
184  return active_;
185 }
186 //*************************************************************************************************
187 
188 
189 
190 
191 //=================================================================================================
192 //
193 // GLOBAL FUNCTIONS
194 //
195 //=================================================================================================
196 
197 //*************************************************************************************************
200 inline bool isSerialSectionActive();
202 //*************************************************************************************************
203 
204 
205 //*************************************************************************************************
212 {
214 }
215 //*************************************************************************************************
216 
217 
218 
219 
220 
221 
222 
223 
224 //=================================================================================================
225 //
226 // SERIAL SECTION MACRO
227 //
228 //=================================================================================================
229 
230 //*************************************************************************************************
260 #define BLAZE_SERIAL_SECTION \
261  if( blaze::SerialSection<int> serialSection = true )
262 //*************************************************************************************************
263 
264 } // namespace blaze
265 
266 #endif
Section to enforce the serial execution of operations.The SerialSection class is an auxiliary helper ...
Definition: SerialSection.h:63
SerialSection(bool activate)
Constructor for the SerialSection class.
Definition: SerialSection.h:138
bool isSerialSectionActive()
Returns whether a serial section is active or not.
Definition: SerialSection.h:211
~SerialSection()
Destructor of the SerialSection class.
Definition: SerialSection.h:160
static bool active_
Activity flag for the serial section.
Definition: SerialSection.h:91