/*
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 1996-1999 by Internet Software Consortium
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* ev_waits.c - implement deferred function calls for the eventlib
* vix 05dec95 [initial]
*/
/*%
* Remove a waiting (or ready to run) function from the queue.
*/
int
evUnwait(evContext opaqueCtx, evWaitID id) {
evContext_p *ctx = opaqueCtx.opaque;
evWait *this, *prev;
evWaitList *wl;
int found = 0;
this = id.opaque;
INSIST(this != NULL);
wl = evGetWaitList(ctx, this->tag, 0);
if (wl != NULL) {
for (prev = NULL, this = wl->first;
this != NULL;
prev = this, this = this->next)
if (this == (evWait *)id.opaque) {
found = 1;
if (prev != NULL)
prev->next = this->next;
else
wl->first = this->next;
if (wl->last == this)
wl->last = prev;
if (wl->first == NULL)
evFreeWaitList(ctx, wl);
break;
}
}
if (!found) {
/* Maybe it's done */
for (prev = NULL, this = ctx->waitDone.first;
this != NULL;
prev = this, this = this->next)
if (this == (evWait *)id.opaque) {
found = 1;
if (prev != NULL)
prev->next = this->next;
else
ctx->waitDone.first = this->next;
if (ctx->waitDone.last == this)
ctx->waitDone.last = prev;
break;
}
}