8 #include "daq/slc/readout/RunInfoBuffer.h"
10 #include <daq/slc/system/LogFile.h>
11 #include <daq/slc/system/LockGuard.h>
18 size_t RunInfoBuffer::size()
20 return m_mutex.size() + m_cond.size() +
24 bool RunInfoBuffer::open(
const std::string& nodename,
25 int nodeid,
bool recreate)
27 m_nodename = nodename;
28 std::string username = getenv(
"USER");
29 m_path =
"/run_info_" + username +
"_" + nodename;
30 if (!m_memory.open(m_path, size())) {
32 LogFile::fatal(
"Failed to open %s", m_path.c_str());
35 char* buf = (
char*)m_memory.map(0, size());
40 buf += m_mutex.size();
45 if (nodeid > 0) setNodeId(nodeid);
49 bool RunInfoBuffer::init()
51 if (m_info == NULL)
return false;
55 LogFile::debug(
"Initialized %s", m_path.c_str());
59 void RunInfoBuffer::clear()
61 if (m_info == NULL)
return;
66 bool RunInfoBuffer::close()
72 bool RunInfoBuffer::unlink()
79 bool RunInfoBuffer::lock()
81 if (m_info == NULL)
return false;
82 return m_mutex.lock();
85 bool RunInfoBuffer::unlock()
87 if (m_info == NULL)
return false;
88 return m_mutex.unlock();
91 bool RunInfoBuffer::wait()
93 if (m_info == NULL)
return false;
94 return m_cond.wait(m_mutex);
97 bool RunInfoBuffer::wait(
int time)
99 if (m_info == NULL)
return false;
100 return m_cond.wait(m_mutex, time, 0);
103 bool RunInfoBuffer::notify()
105 if (m_info == NULL)
return false;
106 return m_cond.broadcast();
109 bool RunInfoBuffer::waitRunning(
int timeout)
111 if (m_info == NULL)
return false;
113 if (getState() != RunInfoBuffer::RUNNING) {
114 if (!wait(timeout)) {
121 bool RunInfoBuffer::waitReady(
int timeout)
123 if (m_info == NULL)
return false;
125 if (getState() != RunInfoBuffer::READY &&
126 getState() != RunInfoBuffer::RUNNING) {
127 if (!wait(timeout)) {
128 if (getState() != RunInfoBuffer::READY &&
129 getState() != RunInfoBuffer::RUNNING) {
137 bool RunInfoBuffer::reportRunning()
139 if (m_info == NULL)
return false;
141 setState(RunInfoBuffer::RUNNING);
146 bool RunInfoBuffer::reportError(EFlag eflag)
148 if (m_info == NULL)
return false;
155 bool RunInfoBuffer::reportReady()
157 if (m_info == NULL)
return false;
159 setState(RunInfoBuffer::READY);
164 bool RunInfoBuffer::reportNotReady()
166 if (m_info == NULL)
return false;
168 setState(RunInfoBuffer::NOTREADY);
173 void RunInfoBuffer::copyEventHeader(
int* buf)
175 if (m_info == NULL)
return;
Lock Guard for a Mutex instance.
Abstract base class for different kinds of events.