5 void Queue_addItem(Queue *list,QueueItem *item) {
6 if ( pthread_mutex_lock( &list->mutex ) ) {
10 item->next = 0; // just in case
12 list->last->next = item;
17 if ( sem_post( &list->count ) ) {
21 if ( pthread_mutex_unlock( &list->mutex ) ) {
27 QueueItem *Queue_getItem(Queue *list) {
29 if ( sem_wait( &list->count ) ) {
33 if ( pthread_mutex_lock( &list->mutex ) ) {
38 list->head = item->next;
39 if ( list->head == 0 ) {
42 if ( pthread_mutex_unlock( &list->mutex ) ) {
49 void Queue_initialize(Queue *list,int n,size_t size) {
50 if ( pthread_mutex_lock( &list->mutex ) ) {
54 if ( list->head == 0 ) {
56 for ( ; i < n; i++ ) {
57 QueueItem *x = (QueueItem *) calloc( 1, size );
65 sem_init( &list->count, 0, n );
67 if ( pthread_mutex_unlock( &list->mutex ) ) {