Search
lxdream.org :: lxdream :: r1273:32b2a340f8b3
lxdream 0.9.1
released Jun 29
Download Now
changeset1273:32b2a340f8b3
parent1272:0b947d924029
child1274:4dff831f1a2e
authornkeynes
dateSun Mar 18 14:18:18 2012 +1000 (9 years ago)
Fix silly errors in tqueue implementation
src/tqueue.c
1.1 --- a/src/tqueue.c Sat Mar 17 08:36:17 2012 +1000
1.2 +++ b/src/tqueue.c Sun Mar 18 14:18:18 2012 +1000
1.3 @@ -41,7 +41,7 @@
1.4
1.5 /************** Producer thread **************/
1.6 #define TQUEUE_EMPTY() (tqueue.head == tqueue.tail)
1.7 -#define TQUEUE_FULL() ((tqueue.head == tqueue.tail+1) || (tqueue.head == 0 && tqueue.tail == TQUEUE_LENGTH))
1.8 +#define TQUEUE_FULL() ((tqueue.head == tqueue.tail+1) || (tqueue.head == 0 && tqueue.tail == (TQUEUE_LENGTH-1)))
1.9
1.10 static void tqueue_enqueue( tqueue_callback callback, void *data, gboolean sync )
1.11 {
1.12 @@ -50,6 +50,8 @@
1.13 tqueue.tqueue[tqueue.tail].data = data;
1.14 tqueue.tqueue[tqueue.tail].synchronous = sync;
1.15 tqueue.tail++;
1.16 + if( tqueue.tail == TQUEUE_LENGTH )
1.17 + tqueue.tail = 0;
1.18 }
1.19
1.20 /**
1.21 @@ -73,6 +75,7 @@
1.22 */
1.23 int tqueue_send_message( tqueue_callback callback, void *data )
1.24 {
1.25 + int result;
1.26 pthread_mutex_lock(&tqueue.mutex);
1.27 if( TQUEUE_FULL() ) {
1.28 /* Wait for the queue to clear */
1.29 @@ -81,8 +84,9 @@
1.30 tqueue_enqueue( callback, data, TRUE );
1.31 pthread_cond_signal(&tqueue.consumer_wait);
1.32 pthread_cond_wait(&tqueue.producer_sync_wait, &tqueue.mutex);
1.33 - return tqueue.last_result;
1.34 + result = tqueue.last_result;
1.35 pthread_mutex_unlock(&tqueue.mutex);
1.36 + return result;
1.37 }
1.38
1.39 /************** Consumer thread **************/
1.40 @@ -95,6 +99,8 @@
1.41 void *data = tqueue.tqueue[tqueue.head].data;
1.42 gboolean sync = tqueue.tqueue[tqueue.head].synchronous;
1.43 tqueue.head++;
1.44 + if( tqueue.head == TQUEUE_LENGTH )
1.45 + tqueue.head = 0;
1.46
1.47 if( wasFull ) {
1.48 pthread_cond_signal( &tqueue.producer_full_wait );
.