Belle II Software development
EvtBuffer Class Reference

Public Member Functions

 EvtBuffer (int id)
 
bool write (int *buf, int nbyte)
 
bool writable ()
 
int * buffer ()
 
void read (Writer &writer)
 
void lock ()
 
void unlock ()
 
void signal ()
 

Private Attributes

int m_id
 
int * m_evtbuf
 
Mutex m_mutex
 
Cond m_cond
 
bool m_writable
 
bool m_readable
 

Detailed Description

Definition at line 39 of file stevtserver.cc.

Constructor & Destructor Documentation

◆ EvtBuffer()

EvtBuffer ( int  id)
inline

Definition at line 42 of file stevtserver.cc.

43 {
44 m_id = id;
45 m_evtbuf = new int[NWORD_BUFFER];
46 m_writable = true;
47 m_readable = false;
48 }

Member Function Documentation

◆ buffer()

int * buffer ( )
inline

Definition at line 75 of file stevtserver.cc.

76 {
77 m_writable = false;
78 m_readable = true;
79 return m_evtbuf;
80 }

◆ lock()

void lock ( )
inline

Definition at line 101 of file stevtserver.cc.

101{ m_mutex.lock(); }

◆ read()

void read ( Writer writer)
inline

Definition at line 81 of file stevtserver.cc.

82 {
83 m_mutex.lock();
84 while (true) {
85 if (!m_readable) {
86 m_cond.wait(m_mutex);
87 } else {
88 //int evtno = m_evtbuf[4];
89 //LogFile::info("write %d %d", m_id, evtno);
90 writer.write(m_evtbuf, m_evtbuf[0] * 4);
91 m_writable = true;
92 m_readable = false;
93 g_mutex.lock();
94 g_cond.signal();
95 g_mutex.unlock();
96 break;
97 }
98 }
99 m_mutex.unlock();
100 }

◆ signal()

void signal ( )
inline

Definition at line 103 of file stevtserver.cc.

103{ m_cond.signal(); }

◆ unlock()

void unlock ( )
inline

Definition at line 102 of file stevtserver.cc.

102{ m_mutex.unlock(); }

◆ writable()

bool writable ( )
inline

Definition at line 65 of file stevtserver.cc.

66 {
67 m_mutex.lock();
68 bool succeded = false;
69 if (m_writable) {
70 succeded = true;
71 }
72 m_mutex.unlock();
73 return succeded;
74 }

◆ write()

bool write ( int *  buf,
int  nbyte 
)
inline

Definition at line 51 of file stevtserver.cc.

52 {
53 m_mutex.lock();
54 bool succeded = false;
55 if (m_writable) {
56 memcpy(m_evtbuf, buf, nbyte);
57 m_cond.signal();
58 m_writable = false;
59 m_readable = true;
60 succeded = true;
61 }
62 m_mutex.unlock();
63 return succeded;
64 }

Member Data Documentation

◆ m_cond

Cond m_cond
private

Definition at line 109 of file stevtserver.cc.

◆ m_evtbuf

int* m_evtbuf
private

Definition at line 107 of file stevtserver.cc.

◆ m_id

int m_id
private

Definition at line 106 of file stevtserver.cc.

◆ m_mutex

Mutex m_mutex
private

Definition at line 108 of file stevtserver.cc.

◆ m_readable

bool m_readable
private

Definition at line 111 of file stevtserver.cc.

◆ m_writable

bool m_writable
private

Definition at line 110 of file stevtserver.cc.


The documentation for this class was generated from the following file: