00001 #ifndef ARTDAQ_CORE_UTILITIES_TRACELOCK
00002 #define ARTDAQ_CORE_UTILITIES_TRACELOCK_HH 1
00003
00004 #include <mutex>
00005 #include "tracemf.h"
00006
00010 class TraceLock
00011 {
00012 public:
00019 TraceLock(std::mutex& mutex, int level, std::string description);
00020
00024 virtual ~TraceLock();
00025
00026 private:
00027 std::unique_lock<std::mutex> lock_;
00028 std::string description_;
00029 int level_;
00030 };
00031
00032 inline TraceLock::TraceLock(std::mutex& mutex, int level, std::string description)
00033 : lock_(mutex)
00034 , description_(description)
00035 , level_(level)
00036 {
00037 TLOG_ARB(level_, "TraceLock") << "Acquired Lock " << description_ << ", mutex=" << (void*)&mutex << ", lock=" << (void*)&lock_;
00038 }
00039
00040 inline TraceLock::~TraceLock()
00041 {
00042 TLOG_ARB(level_, "TraceLock") << "Releasing lock " << description_ << ", lock=" << (void*)&lock_;
00043 }
00044
00045 #endif