From 8d80c132b5b2c71718722dee321f739374dd731e Mon Sep 17 00:00:00 2001 From: Scott Lindeneau Date: Thu, 21 Aug 2008 04:35:01 +0900 Subject: [PATCH] Fixes a bug in the async implementation. When checking for waiting elements on a queue you need to check to see if ANY element is waiting, not just the first element. When waking elements up you should ALERT an element that is not already alerted. All other status messages should be set. (This compensates for poll events that trigger other poll events before garbage collection occurs and removes alerted elements from the queues). --- server/async.c | 20 ++++++++++++++++---- 1 files changed, 16 insertions(+), 4 deletions(-) diff --git a/server/async.c b/server/async.c index 879616d..83476ce 100644 --- a/server/async.c +++ b/server/async.c @@ -279,13 +279,20 @@ void async_set_result( struct object *obj, unsigned int status, unsigned long to /* check if an async operation is waiting to be alerted */ int async_waiting( struct async_queue *queue ) { - struct list *ptr; + struct list *ptr,*next; struct async *async; if (!queue) return 0; if (!(ptr = list_head( &queue->queue ))) return 0; - async = LIST_ENTRY( ptr, struct async, queue_entry ); - return async->status == STATUS_PENDING; + LIST_FOR_EACH_SAFE( ptr, next, &queue->queue ) + { + async = LIST_ENTRY( ptr, struct async, queue_entry ); + if(async->status == STATUS_PENDING) + { /*something is pending*/ + return TRUE; + } + } + return FALSE; /*nothing is pending*/ } /* wake up async operations on the queue */ @@ -299,6 +306,11 @@ void async_wake_up( struct async_queue *queue, unsigned int status ) { struct async *async = LIST_ENTRY( ptr, struct async, queue_entry ); async_terminate( async, status ); - if (status == STATUS_ALERTED) break; /* only wake up the first one */ + if( ((status == STATUS_ALERTED) && (async->status != STATUS_ALERTED) || /*don't alert one thats already alerted*/ + (status != STATUS_ALERTED)) ) /*if we aren't alerting, notify everything*/ + { + async_terminate( async, status ); + if (status == STATUS_ALERTED) break; /* only wake up the first one */ + } } } -- 1.5.4.3