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 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 aioClose(int fd) { aio_ctrl_t *ctrlp; assert(initialised); aio_counts.close++; aioCancel(fd); ctrlp = memPoolAlloc(aio_ctrl_pool); ctrlp->fd = fd; ctrlp->done_handler = NULL; ctrlp->done_handler_data = NULL; ctrlp->operation = _AIO_CLOSE; if (aio_close(fd, &ctrlp->result) < 0) { close(fd); /* Can't create thread - do a normal close */ memPoolFree(aio_ctrl_pool, ctrlp); aioFDWasClosed(fd); return; } ctrlp->next = used_list; used_list = ctrlp; return; }