BOSS 7.0.4
BESIII Offline Software System
Loading...
Searching...
No Matches
PthrWriterBufPool< Writer, PoolSize > Class Template Reference

#include <PthrWriterBufPool.h>

+ Inheritance diagram for PthrWriterBufPool< Writer, PoolSize >:

Public Member Functions

 PthrWriterBufPool (typename Writer::WriterArgType &arg)
 
virtual ~PthrWriterBufPool ()
 
int writeEvent (void *pevt, int size)
 
int stat ()
 
 PthrWriterBufPool (typename Writer::WriterArgType &arg)
 
virtual ~PthrWriterBufPool ()
 
int writeEvent (void *pevt, int size)
 
int stat ()
 

Detailed Description

template<typename Writer, int PoolSize = 8>
class PthrWriterBufPool< Writer, PoolSize >

Definition at line 11 of file DistBoss/DistBossUtil/DistBossUtil-00-00-04/DistBossUtil/PthrWriterBufPool.h.

Constructor & Destructor Documentation

◆ PthrWriterBufPool() [1/2]

template<typename Writer , int PoolSize>
PthrWriterBufPool< Writer, PoolSize >::PthrWriterBufPool ( typename Writer::WriterArgType &  arg)

Definition at line 19 of file DistBoss/DistBossUtil/DistBossUtil-00-00-04/DistBossUtil/template/PthrWriterBufPool.cc.

20 : m_inLoop(-1),
21 m_outLoop(-1)
22{
23 if ( PoolSize < 2 ) {
24 std::cout << "[PthrWriterBufPool] The PoolSize of buffer must > 1" << std::endl;
25 exit(1);
26 }
27
28 // use(PoolSize-1) to protect the current event buffer
29 sem_init(&m_semIn, 0, (PoolSize-1));
30 sem_init(&m_semOut, 0, 0);
31 sem_init(&m_semFinalize, 0, 0);
32
33 for ( int i = 0; i < PoolSize; ++i ) {
34 // buffer in the loop for each event
35 m_buf[i] = new AutoEnlargeBuffer(128*1024);
36 }
37
38 m_writer = new Writer(arg);
39
40 // create an individual thread for writing
41 pthread_create(&m_tid, NULL, thread_writing, (void*)this);
42}
double arg(const EvtComplex &c)
Definition: EvtComplex.hh:227

◆ ~PthrWriterBufPool() [1/2]

template<typename Writer , int PoolSize>
PthrWriterBufPool< Writer, PoolSize >::~PthrWriterBufPool
virtual

Definition at line 45 of file DistBoss/DistBossUtil/DistBossUtil-00-00-04/DistBossUtil/template/PthrWriterBufPool.cc.

46{
47 // wait for the end of thread_writing
48 sem_wait(&m_semFinalize);
49
50 for ( int i = 0; i < PoolSize; ++i ) {
51 delete m_buf[i];
52 }
53
54 sem_destroy(&m_semIn);
55 sem_destroy(&m_semOut);
56 sem_destroy(&m_semFinalize);
57
58 delete m_writer;
59}

◆ PthrWriterBufPool() [2/2]

template<typename Writer , int PoolSize = 8>
PthrWriterBufPool< Writer, PoolSize >::PthrWriterBufPool ( typename Writer::WriterArgType &  arg)

◆ ~PthrWriterBufPool() [2/2]

template<typename Writer , int PoolSize = 8>
virtual PthrWriterBufPool< Writer, PoolSize >::~PthrWriterBufPool ( )
virtual

Member Function Documentation

◆ stat() [1/2]

template<typename Writer , int PoolSize>
int PthrWriterBufPool< Writer, PoolSize >::stat
virtual

Implements IRawWriter.

Definition at line 78 of file DistBoss/DistBossUtil/DistBossUtil-00-00-04/DistBossUtil/template/PthrWriterBufPool.cc.

79{
80 return m_writer->stat();
81}

◆ stat() [2/2]

template<typename Writer , int PoolSize = 8>
int PthrWriterBufPool< Writer, PoolSize >::stat ( )
virtual

Implements IRawWriter.

◆ writeEvent() [1/2]

template<typename Writer , int PoolSize>
int PthrWriterBufPool< Writer, PoolSize >::writeEvent ( void *  pevt,
int  size 
)
virtual

Implements IRawWriter.

Definition at line 62 of file DistBoss/DistBossUtil/DistBossUtil-00-00-04/DistBossUtil/template/PthrWriterBufPool.cc.

63{
64 if ( m_writer->stat() != 0 ) return m_writer->stat();
65
66 sem_wait(&m_semIn);
67
68 int index = (++m_inLoop) % PoolSize;
69
70 m_buf[index]->copy( pevt, size );
71
72 sem_post(&m_semOut);
73
74 return 0;
75}

Referenced by EventWriter::execute(), EventWriter::finalize(), and EventWriter::initialize().

◆ writeEvent() [2/2]

template<typename Writer , int PoolSize = 8>
int PthrWriterBufPool< Writer, PoolSize >::writeEvent ( void *  pevt,
int  size 
)
virtual

Implements IRawWriter.


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