CMS 3D CMS Logo

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  public:
40  CallNTimesNoWait(unsigned short iNTimes) : m_ntimes(static_cast<int>(iNTimes) - 1), m_done(false) {}
41 
42  template <typename T>
43  void operator()(T iCall) {
44  if (not m_done.load(std::memory_order_acquire)) {
45  if (m_ntimes.fetch_sub(1, std::memory_order_acq_rel) < 0) {
46  m_done.store(true, std::memory_order_release);
47  return;
48  };
49  iCall();
50  }
51  }
52 
53  private:
54  std::atomic<int> m_ntimes;
55  std::atomic<bool> m_done;
56  };
57 } // namespace edm
58 
59 #endif
CallNTimesNoWait(unsigned short iNTimes)
void operator()(T iCall)
std::atomic< int > m_ntimes
std::atomic< bool > m_done
HLT enums.
long double T