artdaq_core  v3_05_00
TraceLock.hh
1 #ifndef ARTDAQ_CORE_UTILITIES_TRACELOCK
2 #define ARTDAQ_CORE_UTILITIES_TRACELOCK_HH 1
3 
4 #include "tracemf.h"
5 #include <mutex>
6 
10 class TraceLock {
11  public:
18  TraceLock(std::mutex& mutex,int level, std::string description);
19 
23  virtual ~TraceLock();
24 
25  private:
26  std::unique_lock<std::mutex> lock_;
27  std::string description_;
28  int level_;
29 };
30 
31 inline TraceLock::TraceLock(std::mutex& mutex,int level, std::string description)
32  : lock_(mutex)
33  , description_(description)
34  , level_(level)
35 {
36  TLOG_ARB(level_, "TraceLock") << "Acquired Lock " << description_ << ", mutex=" << (void*)&mutex << ", lock=" << (void*)&lock_ ;
37 }
38 
40  TLOG_ARB(level_, "TraceLock") << "Releasing lock " << description_ << ", lock=" << (void*)&lock_ ;
41 }
42 
43 #endif
44 
TraceLock(std::mutex &mutex, int level, std::string description)
Construct a TraceLock.
Definition: TraceLock.hh:31
The TraceLock class allows a user to debug the acquisition and releasing of locks, by wrapping the unique_lock&lt;std::mutex&gt; API with TRACE calls.
Definition: TraceLock.hh:10
virtual ~TraceLock()
Release the TraceLock.
Definition: TraceLock.hh:39