18template <
typename Writer,
int PoolSize>
24 std::cout <<
"[PthrWriterBufPool] The PoolSize of buffer must > 1" << std::endl;
29 sem_init(&m_semIn, 0, (PoolSize-1));
30 sem_init(&m_semOut, 0, 0);
31 sem_init(&m_semFinalize, 0, 0);
33 for (
int i = 0; i < PoolSize; ++i ) {
38 m_writer =
new Writer(
arg);
41 pthread_create(&m_tid, NULL, thread_writing, (
void*)
this);
44template <
typename Writer,
int PoolSize>
48 sem_wait(&m_semFinalize);
50 for (
int i = 0; i < PoolSize; ++i ) {
54 sem_destroy(&m_semIn);
55 sem_destroy(&m_semOut);
56 sem_destroy(&m_semFinalize);
61template <
typename Writer,
int PoolSize>
64 if ( m_writer->stat() != 0 )
return m_writer->stat();
68 int index = (++m_inLoop) % PoolSize;
70 m_buf[index]->copy( pevt, size );
77template <
typename Writer,
int PoolSize>
80 return m_writer->stat();
83template <
typename Writer,
int PoolSize>
94 sem_post(&(pthis->m_semIn));
96 sem_wait(&(pthis->m_semOut));
98 index = (++(pthis->m_outLoop)) % PoolSize;
100 pbuf = pthis->m_buf[index];
103 pthis->m_writer->writeEvent( pbuf->
data(), pbuf->
size() );
114 std::cout <<
"[PthrWriterBufPool] Catch unexpected exception !" << std::endl;
120 pthis->m_writer->close();
122 sem_post(&(pthis->m_semFinalize));
double arg(const EvtComplex &c)
int writeEvent(void *pevt, int size)
virtual ~PthrWriterBufPool()
virtual void print() const