artdaq_core  v3_06_00
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 template<typename MUTEX = std::mutex>
11 class TraceLock
12 {
13 public:
20  TraceLock(MUTEX& mutex, int level, std::string const& description)
21  : lock_(mutex)
22  , description_(description)
23  , level_(level)
24  {
25  TLOG_ARB(level_, "TraceLock") << "Acquired Lock " << description_ << ", mutex=" << (void*)&mutex << ", lock=" << (void*)&lock_; // NOLINT(google-readability-casting)
26  }
27 
31  virtual ~TraceLock()
32  {
33  TLOG_ARB(level_, "TraceLock") << "Releasing lock " << description_ << ", lock=" << (void*)&lock_; // NOLINT(google-readability-casting)
34  }
35 
36 private:
37  TraceLock(TraceLock const&) = delete;
38  TraceLock(TraceLock&&) = delete;
39  TraceLock& operator=(TraceLock const&) = delete;
40  TraceLock& operator=(TraceLock&&) = delete;
41 
42  std::unique_lock<MUTEX> lock_;
43  std::string description_;
44  int level_;
45 };
46 
47 #endif
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:11
virtual ~TraceLock()
Release the TraceLock.
Definition: TraceLock.hh:31
TraceLock(MUTEX &mutex, int level, std::string const &description)
Construct a TraceLock.
Definition: TraceLock.hh:20