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 #include <blaze/util/Suffix.h>
45 
46 
47 namespace blaze {
48 
49 //=================================================================================================
50 //
51 // CLASS DEFINITION
52 //
53 //=================================================================================================
54 
55 //*************************************************************************************************
63 template< 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_;
93 
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 //*************************************************************************************************
118 template< typename T >
119 bool SerialSection<T>::active_ = false;
121 //*************************************************************************************************
122 
123 
124 
125 
126 //=================================================================================================
127 //
128 // CONSTRUCTOR
129 //
130 //=================================================================================================
131 
132 //*************************************************************************************************
138 template< typename T >
139 inline SerialSection<T>::SerialSection( bool activate )
140 {
141  if( active_ )
142  throw std::runtime_error( "Nested serial sections detected" );
143 
144  active_ = activate;
145 }
146 //*************************************************************************************************
147 
148 
149 
150 
151 //=================================================================================================
152 //
153 // DESTRUCTOR
154 //
155 //=================================================================================================
156 
157 //*************************************************************************************************
160 template< typename T >
162 {
163  active_ = false; // Resetting the activity flag
164 }
165 //*************************************************************************************************
166 
167 
168 
169 
170 //=================================================================================================
171 //
172 // CONVERSION OPERATOR
173 //
174 //=================================================================================================
175 
176 //*************************************************************************************************
182 template< typename T >
183 inline SerialSection<T>::operator bool() const
184 {
185  return active_;
186 }
187 //*************************************************************************************************
188 
189 
190 
191 
192 //=================================================================================================
193 //
194 // GLOBAL FUNCTIONS
195 //
196 //=================================================================================================
197 
198 //*************************************************************************************************
201 inline bool isSerialSectionActive();
203 //*************************************************************************************************
204 
205 
206 //*************************************************************************************************
213 {
215 }
216 //*************************************************************************************************
217 
218 
219 
220 
221 
222 
223 
224 
225 //=================================================================================================
226 //
227 // SERIAL SECTION MACRO
228 //
229 //=================================================================================================
230 
231 //*************************************************************************************************
261 #define BLAZE_SERIAL_SECTION \
262  if( blaze::SerialSection<int> BLAZE_JOIN( serialSection, __LINE__ ) = true )
263 //*************************************************************************************************
264 
265 } // namespace blaze
266 
267 #endif
Section to enforce the serial execution of operations.The SerialSection class is an auxiliary helper ...
Definition: SerialSection.h:64
SerialSection(bool activate)
Constructor for the SerialSection class.
Definition: SerialSection.h:139
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
bool isSerialSectionActive()
Returns whether a serial section is active or not.
Definition: SerialSection.h:212
~SerialSection()
Destructor of the SerialSection class.
Definition: SerialSection.h:161
Header file for compile time constraints.
static bool active_
Activity flag for the serial section.
Definition: SerialSection.h:92