8#include "daq/slc/readout/RunInfoBuffer.h"
10#include <daq/slc/system/LogFile.h>
11#include <daq/slc/system/LockGuard.h>
18size_t RunInfoBuffer::size()
20 return m_mutex.size() + m_cond.size() +
24bool 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);
49bool RunInfoBuffer::init()
51 if (m_info == NULL)
return false;
55 LogFile::debug(
"Initialized %s", m_path.c_str());
59void RunInfoBuffer::clear()
61 if (m_info == NULL)
return;
66bool RunInfoBuffer::close()
72bool RunInfoBuffer::unlink()
79bool RunInfoBuffer::lock()
81 if (m_info == NULL)
return false;
82 return m_mutex.lock();
85bool RunInfoBuffer::unlock()
87 if (m_info == NULL)
return false;
88 return m_mutex.unlock();
91bool RunInfoBuffer::wait()
93 if (m_info == NULL)
return false;
94 return m_cond.wait(m_mutex);
97bool RunInfoBuffer::wait(
int time)
99 if (m_info == NULL)
return false;
100 return m_cond.wait(m_mutex, time, 0);
103bool RunInfoBuffer::notify()
105 if (m_info == NULL)
return false;
106 return m_cond.broadcast();
109bool RunInfoBuffer::waitRunning(
int timeout)
111 if (m_info == NULL)
return false;
113 if (getState() != RunInfoBuffer::RUNNING) {
114 if (!wait(timeout)) {
121bool 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) {
137bool RunInfoBuffer::reportRunning()
139 if (m_info == NULL)
return false;
141 setState(RunInfoBuffer::RUNNING);
146bool RunInfoBuffer::reportError(EFlag eflag)
148 if (m_info == NULL)
return false;
155bool RunInfoBuffer::reportReady()
157 if (m_info == NULL)
return false;
159 setState(RunInfoBuffer::READY);
164bool RunInfoBuffer::reportNotReady()
166 if (m_info == NULL)
return false;
168 setState(RunInfoBuffer::NOTREADY);
173void RunInfoBuffer::copyEventHeader(
int* buf)
175 if (m_info == NULL)
return;
Lock Guard for a Mutex instance.
Abstract base class for different kinds of events.