14 Queue::Queue(
int qMax1) {
22 pthread_mutex_destroy(&
lock);
23 pthread_cond_destroy(&
emptyQ);
24 pthread_cond_destroy(&
fullQ);
31 pthread_mutex_lock(&
lock);
33 pthread_mutex_unlock(&
lock);
37 int status = pthread_mutex_init(&
lock,NULL);
38 if (status != 0)
return false;
39 status = (pthread_cond_init(&
emptyQ,NULL) == 0) &&
40 (pthread_cond_init(&
fullQ,NULL) == 0);
49 pthread_mutex_lock(&
lock);
58 pthread_mutex_unlock(&
lock);
59 if (pthread_cond_signal(&
emptyQ) != 0)
60 cerr <<
"pthread_cond_signal on emptyQ failed";
68 pthread_mutex_lock(&
lock);
77 pthread_mutex_unlock(&
lock);
78 pthread_cond_signal(&
fullQ);
90 pthread_mutex_lock(&
lock);
94 gettimeofday(&now,NULL);
96 targetTime.tv_sec = now.tv_sec;
97 targetTime.tv_nsec = 1000 * now.tv_usec;
98 int dsec = timeout/1000000000;
99 int dnsec = timeout%1000000000;
100 targetTime.tv_sec += dsec;
101 targetTime.tv_nsec += dnsec;
102 if (targetTime.tv_nsec > 1000000000) {
103 targetTime.tv_sec++; targetTime.tv_nsec -= 1000000000;
107 while (
count == 0 && status != ETIMEDOUT) {
108 status = pthread_cond_timedwait(&
emptyQ,&
lock,&targetTime);
111 if (status == ETIMEDOUT) {
112 retVal = Queue::TIMEOUT;
118 pthread_mutex_unlock(&
lock);
119 pthread_cond_signal(&
fullQ);