21 #include <semaphore.h>
25 #include "StaticSizedDQueue.hh"
34 int send(T* a,
int prio = 0 ) ;
35 int receive(T*,
int block=1) ;
39 int entries() {
return(q->entries()) ;} ;
40 int free() {
return(q->free()) ;} ;
53 pthread_mutexattr_t mattr ;
64 sema_destroy(&occupied) ;
68 sem_destroy(&occupied) ;
69 pthread_mutex_destroy(&mp) ;
81 mutex_init(&mp,USYNC_THREAD,NULL);
82 sema_init(&empty,elements,USYNC_THREAD,NULL) ;
83 sema_init(&occupied,0,USYNC_THREAD,NULL) ;
85 pthread_mutex_init(&mp,NULL);
86 sem_init(&empty,0,elements) ;
87 sem_init(&occupied,0,0) ;
91 #if defined(linux) || defined(__APPLE__)
101 iret = sema_wait(&empty);
103 iret = sem_wait(&empty) ;
107 if(errno == EINTR)
goto l1 ;
113 pthread_mutex_lock(&mp) ;
117 iret = q->prepend(a) ;
119 iret = q->insert(a) ;
124 pthread_mutex_unlock(&mp);
133 sema_post(&occupied) ;
135 sem_post(&occupied) ;
149 iret = sema_wait(&occupied);
151 iret = sem_wait(&occupied);
155 iret = sem_trywait(&occupied);
164 if(errno == EINTR)
goto l1;
171 pthread_mutex_lock(&mp) ;
179 pthread_mutex_unlock(&mp) ;
203 pthread_mutex_lock(&mp) ;
204 iret = sem_getvalue(&occupied, &semval);
213 pthread_mutex_unlock(&mp) ;