test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CallNTimesNoWait.h
Go to the documentation of this file.
1 #ifndef FWCore_Utilities_CallNTimesNoWait_h
2 #define FWCore_Utilities_CallNTimesNoWait_h
3 // -*- C++ -*-
4 //
5 // Package: FWCore/Utilities
6 // Class : CallNTimesNoWait
7 //
26 //
27 // Original Author: Chris Jones
28 // Created: Fri, 15 Nov 2013 14:29:41 GMT
29 //
30 
31 // system include files
32 #include<atomic>
33 
34 // user include files
35 
36 // forward declarations
37 namespace edm {
39  {
40 
41  public:
42  CallNTimesNoWait( unsigned short iNTimes ): m_ntimes(static_cast<int>(iNTimes)-1), m_done(false){}
43 
44  template <typename T>
45  void operator()(T iCall) {
46  if(not m_done.load(std::memory_order_acquire) ) {
47  if(m_ntimes.fetch_sub(1,std::memory_order_acq_rel)<0) {
48  m_done.store(true,std::memory_order_release);
49  return;
50  };
51  iCall();
52  }
53  }
54 
55  private:
56  std::atomic<int> m_ntimes;
57  std::atomic<bool> m_done;
58  };
59 }
60 
61 #endif
CallNTimesNoWait(unsigned short iNTimes)
void operator()(T iCall)
std::atomic< int > m_ntimes
std::atomic< bool > m_done
volatile std::atomic< bool > shutdown_flag false
long double T