From 649f8b0429dc1b25d65c34ee461e448d8f56f410 Mon Sep 17 00:00:00 2001 From: paulo Date: Mon, 25 Jan 2010 16:18:53 +0000 Subject: Fixed problems in mqueue keeping tail pointers correct. Implemented program terminate code that waits for all sissions to become disabled before terminating pthreads and running exit code. --- lib/mqueue.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'lib/mqueue.c') diff --git a/lib/mqueue.c b/lib/mqueue.c index f252586e..3031891e 100644 --- a/lib/mqueue.c +++ b/lib/mqueue.c @@ -434,11 +434,15 @@ mqueue_enqueue(mqueue_queue mq, mqueue_block mqb, int priority) { mqb->next = mq->head ; mq->head = mqb ; + /* mq non-empty, enchain at head, therefore tail unaffected */ } else { mqb->next = after->next ; after->next = mqb ; + /* if only have priority messages then fix tail */ + if (mq->tail == after) + mq->tail = mqb; } mq->tail_priority = mqb ; } @@ -593,6 +597,10 @@ mqueue_dequeue(mqueue_queue mq, int wait, void* arg) /* Have something to pull off the queue */ mq->head = mqb->next ; + + /* fix tails if at tail */ + if (mqb == mq->tail) + mq->tail = NULL ; if (mqb == mq->tail_priority) mq->tail_priority = NULL ; @@ -644,6 +652,9 @@ mqueue_revoke(mqueue_queue mq, void* arg0) if (mq->tail == mqb) mq->tail = prev ; + if (mqb == mq->tail_priority) + mq->tail_priority = prev ; + qpt_mutex_unlock(&mq->mutex) ; mqb_dispatch_destroy(mqb) ; qpt_mutex_lock(&mq->mutex) ; -- cgit v1.2.3