CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Attributes
edm::CallOnceNoWait Class Reference

#include "FWCore/Utilities/interface/CallOnceNoWait.h"

Public Member Functions

 CallOnceNoWait ()
 
template<typename T >
void operator() (T iCall)
 

Private Attributes

std::atomic< bool > m_called
 

Detailed Description

Description: Thread safe way to do something 1 time

Usage: This class allows one to safely do a 'non-side-effect' operation 1 time in a job. An example use would be

void myFunc( int iValue) {
message([&]() { edm::LogInfo("IWantToKnow")<<"called with "<<iValue; } );

The important thing to remember, is there is no guarantee that the operation being run finishes before a thread which doesn't get to run the operation reaches the code following the call. Therefore it is useful to suppress messages but should not be used to do something like filling a container with values since the filling is not guaranteed to complete before another thread skips the call.

Definition at line 40 of file CallOnceNoWait.h.

Constructor & Destructor Documentation

edm::CallOnceNoWait::CallOnceNoWait ( )
inline

Definition at line 43 of file CallOnceNoWait.h.

43 : m_called(false) {}
std::atomic< bool > m_called

Member Function Documentation

template<typename T >
void edm::CallOnceNoWait::operator() ( T  iCall)
inline

Definition at line 46 of file CallOnceNoWait.h.

References m_called.

46  {
47  bool expected = false;
48  if(m_called.compare_exchange_strong(expected, true, std::memory_order_acq_rel)) {
49  iCall();
50  }
51  }
std::atomic< bool > m_called

Member Data Documentation

std::atomic<bool> edm::CallOnceNoWait::m_called
private

Definition at line 54 of file CallOnceNoWait.h.

Referenced by operator()().