18template <
typename Reader,
int PoolSize>
25 std::cout <<
"[PthrReaderBufPool] The PoolSize of buffer must > 1" << std::endl;
30 sem_init(&m_semIn, 0, (PoolSize-1));
31 sem_init(&m_semOut, 0, 0);
32 pthread_mutex_init(&m_lock, NULL);
34 sem_init(&m_semSyn, 0, 0);
36 for (
int i = 0; i < PoolSize; ++i ) {
41 m_reader =
new Reader(
arg);
44 pthread_create(&m_tid, NULL, thread_filling, (
void*)
this);
47template <
typename Reader,
int PoolSize>
50 for (
int i = 0; i < PoolSize; ++i ) {
54 delete m_RawFileException;
56 sem_destroy(&m_semIn);
57 sem_destroy(&m_semOut);
62template <
typename Reader,
int PoolSize>
65 if ( m_outLoop < 0 ) sem_post(&m_semSyn);
72 pthread_mutex_lock(&m_lock);
73 int inLoop = m_inLoop;
74 pthread_mutex_unlock(&m_lock);
76 if ( m_RawFileException != 0 && m_outLoop >= inLoop ) {
87 const uint32_t* pevt = (uint32_t*)m_buf[ m_outLoop%PoolSize ]->
data();
91template <
typename Reader,
int PoolSize>
95 const uint32_t* pevt = (uint32_t*)m_buf[ m_outLoop%PoolSize ]->
data();
99template <
typename Reader,
int PoolSize>
102 return m_reader->runNo();
105template <
typename Reader,
int PoolSize>
108 return m_reader->currentFile();
111template <
typename Reader,
int PoolSize>
114 return m_reader->stat();
117template <
typename Reader,
int PoolSize>
123 const uint32_t* pevt;
125 sem_wait(&(pthis->m_semSyn));
129 sem_wait(&(pthis->m_semIn));
132 pevt = pthis->m_reader->nextEvent();
143 std::cout <<
"[PthrReaderBufPool] Catch unexpected exception !" << std::endl;
147 pthread_mutex_lock(&(pthis->m_lock));
148 index = (++(pthis->m_inLoop)) % PoolSize;
149 pthread_mutex_unlock(&(pthis->m_lock));
151 pthis->m_buf[index]->
copy( (
void*)pevt, pevt[1]*
sizeof(uint32_t) );
154 sem_post(&(pthis->m_semOut));
157 sem_post(&(pthis->m_semOut));
double arg(const EvtComplex &c)
void copy(void *src, int size)
std::string currentFile()
virtual ~PthrReaderBufPool()
const uint32_t * nextEvent()
const uint32_t * currentEvent() const