int aioCheckCallbacks(SwapDir * SD) { squidaio_result_t *resultp; squidaio_ctrl_t *ctrlp; AIOCB *done_handler; void *their_data; int retval = 0; assert(initialised); squidaio_counts.check_callback++; for (;;) { if ((resultp = squidaio_poll_done()) == NULL) break; ctrlp = (squidaio_ctrl_t *) resultp->data; if (ctrlp == NULL) continue; /* XXX Should not happen */ dlinkDelete(&ctrlp->node, &used_list); if ((done_handler = ctrlp->done_handler)) { their_data = ctrlp->done_handler_data; ctrlp->done_handler = NULL; ctrlp->done_handler_data = NULL; if (cbdataValid(their_data)) { retval = 1; /* Return that we've actually done some work */ done_handler(ctrlp->fd, their_data, ctrlp->bufp, ctrlp->result.aio_return, ctrlp->result.aio_errno); } else { if (ctrlp->operation == _AIO_OPEN) { /* The open operation was aborted.. */ int fd = ctrlp->result.aio_return; if (fd >= 0) aioClose(fd); } } cbdataUnlock(their_data); } /* free data if requested to aioWrite() */ if (ctrlp->free_func) ctrlp->free_func(ctrlp->bufp); /* free temporary read buffer */ if (ctrlp->operation == _AIO_READ) squidaio_xfree(ctrlp->bufp, ctrlp->len); if (ctrlp->operation == _AIO_CLOSE) aioFDWasClosed(ctrlp->fd); memPoolFree(squidaio_ctrl_pool, ctrlp); } return retval; }
void opq_op_done(opq_t *opq) { ilist_iter_t iter; opq_elem_t *elem; opq_elem_t *list = NULL; opq_elem_t *next; opq_elem_t **list_end = &list; opq_done_cb done_handler; void *done_data; /* First check for done handlers. */ opq_lock(opq); ilist_init_iter(&iter, opq->ops); ilist_first(&iter); elem = ilist_get(&iter); while (elem && (!elem->block)) { ilist_delete(&iter); elem->next = NULL; *list_end = elem; list_end = &(elem->next); elem = ilist_get(&iter); } done_handler = opq->done_handler; done_data = opq->done_data; opq->done_handler = NULL; if (done_handler || list) { /* There are done handlers to call, unlock and call them. */ opq_unlock(opq); if (done_handler) done_handler(done_data, 0); while (list) { next = list->next; list->done(list->done_data, 0); opq_free_elem(list); list = next; } opq_lock(opq); /* During the time we were unlocked, handlers may have been added. */ ilist_first(&iter); elem = ilist_get(&iter); } start_next_op(opq); opq_unlock(opq); }
void aioCancel(int fd) { aio_ctrl_t *curr; aio_ctrl_t *prev; aio_ctrl_t *next; AIOCB *done_handler; void *their_data; assert(initialised); aio_counts.cancel++; prev = NULL; curr = used_list; for (curr = used_list;; curr = next) { while (curr != NULL) { if (curr->fd == fd) break; prev = curr; curr = curr->next; } if (curr == NULL) break; aio_cancel(&curr->result); if ((done_handler = curr->done_handler)) { their_data = curr->done_handler_data; curr->done_handler = NULL; curr->done_handler_data = NULL; debug(32, 2) ("this be aioCancel\n"); if (cbdataValid(their_data)) done_handler(fd, their_data, -2, -2); cbdataUnlock(their_data); } next = curr->next; if (prev == NULL) used_list = next; else prev->next = next; memPoolFree(aio_ctrl_pool, curr); } }
void aioCheckCallbacks(void) { aio_result_t *resultp; aio_ctrl_t *ctrlp; aio_ctrl_t *prev; AIOCB *done_handler; void *their_data; assert(initialised); aio_counts.check_callback++; for (;;) { if ((resultp = aio_poll_done()) == NULL) break; prev = NULL; for (ctrlp = used_list; ctrlp != NULL; prev = ctrlp, ctrlp = ctrlp->next) if (&ctrlp->result == resultp) break; if (ctrlp == NULL) continue; if (prev == NULL) used_list = ctrlp->next; else prev->next = ctrlp->next; if ((done_handler = ctrlp->done_handler)) { their_data = ctrlp->done_handler_data; ctrlp->done_handler = NULL; ctrlp->done_handler_data = NULL; if (cbdataValid(their_data)) done_handler(ctrlp->fd, their_data, ctrlp->result.aio_return, ctrlp->result.aio_errno); cbdataUnlock(their_data); } if (ctrlp->operation == _AIO_CLOSE) aioFDWasClosed(ctrlp->fd); memPoolFree(aio_ctrl_pool, ctrlp); } }
void aioCancel(int fd) { squidaio_ctrl_t *ctrlp; AIOCB *done_handler; void *their_data; dlink_node *m, *next; assert(initialised); squidaio_counts.cancel++; for (m = used_list.head; m; m = next) { next = m->next; ctrlp = m->data; if (ctrlp->fd != fd) continue; squidaio_cancel(&ctrlp->result); if ((done_handler = ctrlp->done_handler)) { their_data = ctrlp->done_handler_data; ctrlp->done_handler = NULL; ctrlp->done_handler_data = NULL; debug(32, 0) ("this be aioCancel. Danger ahead!\n"); if (cbdataValid(their_data)) done_handler(fd, their_data, NULL, -2, -2); cbdataUnlock(their_data); /* free data if requested to aioWrite() */ if (ctrlp->free_func) ctrlp->free_func(ctrlp->bufp); /* free temporary read buffer */ if (ctrlp->operation == _AIO_READ) squidaio_xfree(ctrlp->bufp, ctrlp->len); } dlinkDelete(m, &used_list); memPoolFree(squidaio_ctrl_pool, ctrlp); } }