ATLAS Offline Software
Timeout.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef ATHENAKERNEL_TIMEOUT_H
6 #define ATHENAKERNEL_TIMEOUT_H 1
7 
18 #include "GaudiKernel/ThreadLocalContext.h"
19 #include <atomic>
20 
21 
22 namespace Athena {
23 
24  // Forward declarations
25  class TimeoutMaster;
26 
35  class Timeout {
37  friend class TimeoutMaster;
38 
39  public:
41  static Timeout& instance();
42  static Timeout& instance(const EventContext& ctx);
43 
45  bool reached() const { return m_state; }
46 
47  Timeout() : m_state(false) {}
48 
49  private:
50  std::atomic<bool> m_state;
51  void set() { m_state = true; }
52  void reset() { m_state = false; }
53 
54  // Prevent direct instantiation
57  };
58 
59  inline Timeout& Timeout::instance (const EventContext& ctx) {
61  return *instances.get (ctx);
62  }
63 
65  return instance (Gaudi::Hive::currentContext());
66  }
67 
68 
77  class TimeoutMaster {
78  protected:
80  void setTimeout(Timeout& instance) { instance.set(); }
81 
83  void resetTimeout(Timeout& instance) { instance.reset(); }
84 
89  };
90 
91 } // namespace Athena
92 
93 #endif
Athena::TimeoutMaster::TimeoutMaster
TimeoutMaster(TimeoutMaster &)
Athena::TimeoutMaster::operator=
TimeoutMaster & operator=(const TimeoutMaster &)
Athena::TimeoutMaster::TimeoutMaster
TimeoutMaster()
Prevent direct instantiation.
Definition: Timeout.h:86
instance
std::map< std::string, double > instance
Definition: Run_To_Get_Tags.h:8
SG::SlotSpecificObj
Maintain a set of objects, one per slot.
Definition: AthenaKernel/AthenaKernel/SlotSpecificObj.h:70
Athena::Timeout
Singleton to access the timeout flag.
Definition: Timeout.h:35
Athena::Timeout::set
void set()
Set timeout flag.
Definition: Timeout.h:51
Athena::TimeoutMaster
Class to modify timeout flag.
Definition: Timeout.h:77
Athena
Some weak symbol referencing magic...
Definition: AthLegacySequence.h:21
Athena::Timeout::operator=
Timeout & operator=(const Timeout &)
Athena::Timeout::instance
static Timeout & instance()
Get reference to Timeout singleton.
Definition: Timeout.h:64
Athena::Timeout::reached
bool reached() const
Check if the timeout was reached.
Definition: Timeout.h:45
Athena::Timeout::Timeout
Timeout()
Definition: Timeout.h:47
Athena::Timeout::reset
void reset()
Reset timeout flag.
Definition: Timeout.h:52
Athena::Timeout::Timeout
Timeout(Timeout &)
SlotSpecificObj.h
Maintain a set of objects, one per slot.
Athena::Timeout::m_state
std::atomic< bool > m_state
Timeout flag.
Definition: Timeout.h:50
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
Athena::TimeoutMaster::resetTimeout
void resetTimeout(Timeout &instance)
Reset timeout.
Definition: Timeout.h:83
Athena::TimeoutMaster::setTimeout
void setTimeout(Timeout &instance)
Set timeout.
Definition: Timeout.h:80