artdaq_core  v3_05_07
TraceLock.hh
1 #ifndef ARTDAQ_CORE_UTILITIES_TRACELOCK
2 #define ARTDAQ_CORE_UTILITIES_TRACELOCK_HH 1
3 
4 #include <mutex>
5 #include "tracemf.h"
6 
10 class TraceLock
11 {
12 public:
19  TraceLock(std::mutex& mutex, int level, std::string description);
20 
24  virtual ~TraceLock();
25 
26 private:
27  std::unique_lock<std::mutex> lock_;
28  std::string description_;
29  int level_;
30 };
31 
32 inline TraceLock::TraceLock(std::mutex& mutex, int level, std::string description)
33  : lock_(mutex)
34  , description_(description)
35  , level_(level)
36 {
37  TLOG_ARB(level_, "TraceLock") << "Acquired Lock " << description_ << ", mutex=" << (void*)&mutex << ", lock=" << (void*)&lock_;
38 }
39 
41 {
42  TLOG_ARB(level_, "TraceLock") << "Releasing lock " << description_ << ", lock=" << (void*)&lock_;
43 }
44 
45 #endif
TraceLock(std::mutex &mutex, int level, std::string description)
Construct a TraceLock.
Definition: TraceLock.hh:32
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:40