version 1.10.2.5, 2012/08/01 22:12:39
|
version 1.11, 2012/08/02 13:56:19
|
Line 482 schedAlarm(sched_root_task_t * __restrict root, sched_
|
Line 482 schedAlarm(sched_root_task_t * __restrict root, sched_
|
return task; |
return task; |
} |
} |
|
|
|
#ifdef AIO_SUPPORT |
/* |
/* |
* schedAIO() - Add AIO task to scheduler queue |
* schedAIO() - Add AIO task to scheduler queue |
* |
* |
Line 497 sched_task_t *
|
Line 498 sched_task_t *
|
schedAIO(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, |
schedAIO(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, |
struct aiocb * __restrict acb, void *opt_data, size_t opt_dlen) |
struct aiocb * __restrict acb, void *opt_data, size_t opt_dlen) |
{ |
{ |
#ifndef EVFILT_AIO |
|
sched_SetErr(ENOTSUP, "Not supported kevent() filter"); |
|
return NULL; |
|
#else |
|
sched_task_t *task; |
sched_task_t *task; |
void *ptr; |
void *ptr; |
|
|
if (!root || !func) | if (!root || !func || !acb || !opt_dlen) |
return NULL; |
return NULL; |
|
|
/* get new task */ |
/* get new task */ |
Line 538 schedAIO(sched_root_task_t * __restrict root, sched_ta
|
Line 535 schedAIO(sched_root_task_t * __restrict root, sched_ta
|
task = _sched_unuseTask(task); |
task = _sched_unuseTask(task); |
|
|
return task; |
return task; |
#endif |
|
} |
} |
|
|
/* |
/* |
Line 550 schedAIO(sched_root_task_t * __restrict root, sched_ta
|
Line 546 schedAIO(sched_root_task_t * __restrict root, sched_ta
|
* @fd = file descriptor |
* @fd = file descriptor |
* @buffer = Buffer |
* @buffer = Buffer |
* @buflen = Buffer length |
* @buflen = Buffer length |
|
* @offset = Offset from start of file, if =-1 from current position |
* return: NULL error or !=NULL new queued task |
* return: NULL error or !=NULL new queued task |
*/ |
*/ |
inline sched_task_t * |
inline sched_task_t * |
schedAIORead(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, int fd, |
schedAIORead(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, int fd, |
void *buffer, size_t buflen) | void *buffer, size_t buflen, off_t offset) |
{ |
{ |
#ifndef EVFILT_AIO |
|
sched_SetErr(ENOTSUP, "Not supported kevent() filter"); |
|
return NULL; |
|
#else |
|
struct aiocb *acb; |
struct aiocb *acb; |
off_t off = 0; | off_t off; |
|
|
if (!root || !func) | if (!root || !func || !buffer || !buflen) |
return NULL; |
return NULL; |
else |
|
memset(buffer, 0, buflen); |
|
|
|
|
if (offset == (off_t) -1) { |
|
off = lseek(fd, 0, SEEK_CUR); |
|
if (off == -1) { |
|
LOGERR; |
|
return NULL; |
|
} |
|
} else |
|
off = offset; |
|
|
if (!(acb = malloc(sizeof(struct aiocb)))) { |
if (!(acb = malloc(sizeof(struct aiocb)))) { |
LOGERR; |
LOGERR; |
return NULL; |
return NULL; |
Line 577 schedAIORead(sched_root_task_t * __restrict root, sche
|
Line 577 schedAIORead(sched_root_task_t * __restrict root, sche
|
acb->aio_fildes = fd; |
acb->aio_fildes = fd; |
acb->aio_nbytes = buflen; |
acb->aio_nbytes = buflen; |
acb->aio_buf = buffer; |
acb->aio_buf = buffer; |
off = lseek(fd, 0, SEEK_CUR); | acb->aio_offset = off; |
if (off == -1) { | |
LOGERR; | |
free(acb); | |
return NULL; | |
} else | |
acb->aio_offset = off; | |
acb->aio_sigevent.sigev_notify = SIGEV_KEVENT; |
acb->aio_sigevent.sigev_notify = SIGEV_KEVENT; |
acb->aio_sigevent.sigev_notify_kqueue = root->root_kq; |
acb->aio_sigevent.sigev_notify_kqueue = root->root_kq; |
acb->aio_sigevent.sigev_value.sival_ptr = acb; |
acb->aio_sigevent.sigev_value.sival_ptr = acb; |
Line 595 schedAIORead(sched_root_task_t * __restrict root, sche
|
Line 589 schedAIORead(sched_root_task_t * __restrict root, sche
|
} |
} |
|
|
return schedAIO(root, func, arg, acb, buffer, buflen); |
return schedAIO(root, func, arg, acb, buffer, buflen); |
#endif |
|
} |
} |
|
|
/* |
/* |
Line 607 schedAIORead(sched_root_task_t * __restrict root, sche
|
Line 600 schedAIORead(sched_root_task_t * __restrict root, sche
|
* @fd = file descriptor |
* @fd = file descriptor |
* @buffer = Buffer |
* @buffer = Buffer |
* @buflen = Buffer length |
* @buflen = Buffer length |
|
* @offset = Offset from start of file, if =-1 from current position |
* return: NULL error or !=NULL new queued task |
* return: NULL error or !=NULL new queued task |
*/ |
*/ |
inline sched_task_t * |
inline sched_task_t * |
schedAIOWrite(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, int fd, |
schedAIOWrite(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, int fd, |
void *buffer, size_t buflen) | void *buffer, size_t buflen, off_t offset) |
{ |
{ |
#ifndef EVFILT_AIO |
|
sched_SetErr(ENOTSUP, "Not supported kevent() filter"); |
|
return NULL; |
|
#else |
|
struct aiocb *acb; |
struct aiocb *acb; |
off_t off = 0; | off_t off; |
|
|
if (!root || !func) | if (!root || !func || !buffer || !buflen) |
return NULL; |
return NULL; |
|
|
|
if (offset == (off_t) -1) { |
|
off = lseek(fd, 0, SEEK_CUR); |
|
if (off == -1) { |
|
LOGERR; |
|
return NULL; |
|
} |
|
} else |
|
off = offset; |
|
|
if (!(acb = malloc(sizeof(struct aiocb)))) { |
if (!(acb = malloc(sizeof(struct aiocb)))) { |
LOGERR; |
LOGERR; |
return NULL; |
return NULL; |
Line 632 schedAIOWrite(sched_root_task_t * __restrict root, sch
|
Line 631 schedAIOWrite(sched_root_task_t * __restrict root, sch
|
acb->aio_fildes = fd; |
acb->aio_fildes = fd; |
acb->aio_nbytes = buflen; |
acb->aio_nbytes = buflen; |
acb->aio_buf = buffer; |
acb->aio_buf = buffer; |
off = lseek(fd, 0, SEEK_CUR); | acb->aio_offset = off; |
if (off == -1) { | |
LOGERR; | |
free(acb); | |
return NULL; | |
} else | |
acb->aio_offset = off; | |
acb->aio_sigevent.sigev_notify = SIGEV_KEVENT; |
acb->aio_sigevent.sigev_notify = SIGEV_KEVENT; |
acb->aio_sigevent.sigev_notify_kqueue = root->root_kq; |
acb->aio_sigevent.sigev_notify_kqueue = root->root_kq; |
acb->aio_sigevent.sigev_value.sival_ptr = acb; |
acb->aio_sigevent.sigev_value.sival_ptr = acb; |
Line 650 schedAIOWrite(sched_root_task_t * __restrict root, sch
|
Line 643 schedAIOWrite(sched_root_task_t * __restrict root, sch
|
} |
} |
|
|
return schedAIO(root, func, arg, acb, buffer, buflen); |
return schedAIO(root, func, arg, acb, buffer, buflen); |
|
} |
|
|
|
#ifdef EVFILT_LIO |
|
/* |
|
* schedLIO() - Add AIO bulk tasks to scheduler queue |
|
* |
|
* @root = root task |
|
* @func = task execution function |
|
* @arg = 1st func argument |
|
* @acbs = AIO cb structure addresses |
|
* @opt_data = Optional data |
|
* @opt_dlen = Optional data length |
|
* return: NULL error or !=NULL new queued task |
|
*/ |
|
sched_task_t * |
|
schedLIO(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, |
|
struct aiocb ** __restrict acbs, void *opt_data, size_t opt_dlen) |
|
{ |
|
sched_task_t *task; |
|
void *ptr; |
|
|
|
if (!root || !func || !acbs || !opt_dlen) |
|
return NULL; |
|
|
|
/* get new task */ |
|
if (!(task = _sched_useTask(root))) |
|
return NULL; |
|
|
|
task->task_func = func; |
|
TASK_TYPE(task) = taskLIO; |
|
TASK_ROOT(task) = root; |
|
|
|
TASK_ARG(task) = arg; |
|
TASK_VAL(task) = (u_long) acbs; |
|
|
|
TASK_DATA(task) = opt_data; |
|
TASK_DATLEN(task) = opt_dlen; |
|
|
|
if (root->root_hooks.hook_add.lio) |
|
ptr = root->root_hooks.hook_add.lio(task, NULL); |
|
else |
|
ptr = NULL; |
|
|
|
if (!ptr) { |
|
#ifdef HAVE_LIBPTHREAD |
|
pthread_mutex_lock(&root->root_mtx[taskLIO]); |
#endif |
#endif |
|
TAILQ_INSERT_TAIL(&root->root_lio, TASK_ID(task), task_node); |
|
#ifdef HAVE_LIBPTHREAD |
|
pthread_mutex_unlock(&root->root_mtx[taskLIO]); |
|
#endif |
|
} else |
|
task = _sched_unuseTask(task); |
|
|
|
return task; |
} |
} |
|
|
|
/* |
|
* schedLIORead() - Add list of AIO read tasks to scheduler queue |
|
* |
|
* @root = root task |
|
* @func = task execution function |
|
* @arg = 1st func argument |
|
* @fd = file descriptor |
|
* @bufs = Buffer's list |
|
* @nbufs = Number of Buffers |
|
* @offset = Offset from start of file, if =-1 from current position |
|
* return: NULL error or !=NULL new queued task |
|
*/ |
|
sched_task_t * |
|
schedLIORead(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, int fd, |
|
struct iovec *bufs, size_t nbufs, off_t offset) |
|
{ |
|
struct sigevent sig; |
|
struct aiocb **acb; |
|
off_t off; |
|
register int i; |
|
|
|
if (!root || !func || !bufs || !nbufs) |
|
return NULL; |
|
|
|
if (offset == (off_t) -1) { |
|
off = lseek(fd, 0, SEEK_CUR); |
|
if (off == -1) { |
|
LOGERR; |
|
return NULL; |
|
} |
|
} else |
|
off = offset; |
|
|
|
if (!(acb = calloc(sizeof(void*), nbufs))) { |
|
LOGERR; |
|
return NULL; |
|
} else |
|
memset(acb, 0, sizeof(void*) * nbufs); |
|
for (i = 0; i < nbufs; off += bufs[i++].iov_len) { |
|
acb[i] = malloc(sizeof(struct aiocb)); |
|
if (!acb[i]) { |
|
LOGERR; |
|
for (i = 0; i < nbufs; i++) |
|
if (acb[i]) |
|
free(acb[i]); |
|
free(acb); |
|
return NULL; |
|
} else |
|
memset(acb[i], 0, sizeof(struct aiocb)); |
|
acb[i]->aio_fildes = fd; |
|
acb[i]->aio_nbytes = bufs[i].iov_len; |
|
acb[i]->aio_buf = bufs[i].iov_base; |
|
acb[i]->aio_offset = off; |
|
acb[i]->aio_lio_opcode = LIO_READ; |
|
} |
|
memset(&sig, 0, sizeof sig); |
|
sig.sigev_notify = SIGEV_KEVENT; |
|
sig.sigev_notify_kqueue = root->root_kq; |
|
sig.sigev_value.sival_ptr = acb; |
|
|
|
if (lio_listio(LIO_NOWAIT, acb, nbufs, &sig)) { |
|
LOGERR; |
|
for (i = 0; i < nbufs; i++) |
|
if (acb[i]) |
|
free(acb[i]); |
|
free(acb); |
|
return NULL; |
|
} |
|
|
|
return schedLIO(root, func, arg, (void*) acb, bufs, nbufs); |
|
} |
|
|
|
/* |
|
* schedLIOWrite() - Add list of AIO write tasks to scheduler queue |
|
* |
|
* @root = root task |
|
* @func = task execution function |
|
* @arg = 1st func argument |
|
* @fd = file descriptor |
|
* @bufs = Buffer's list |
|
* @nbufs = Number of Buffers |
|
* @offset = Offset from start of file, if =-1 from current position |
|
* return: NULL error or !=NULL new queued task |
|
*/ |
|
inline sched_task_t * |
|
schedLIOWrite(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, int fd, |
|
struct iovec *bufs, size_t nbufs, off_t offset) |
|
{ |
|
struct sigevent sig; |
|
struct aiocb **acb; |
|
off_t off; |
|
register int i; |
|
|
|
if (!root || !func || !bufs || !nbufs) |
|
return NULL; |
|
|
|
if (offset == (off_t) -1) { |
|
off = lseek(fd, 0, SEEK_CUR); |
|
if (off == -1) { |
|
LOGERR; |
|
return NULL; |
|
} |
|
} else |
|
off = offset; |
|
|
|
if (!(acb = calloc(sizeof(void*), nbufs))) { |
|
LOGERR; |
|
return NULL; |
|
} else |
|
memset(acb, 0, sizeof(void*) * nbufs); |
|
for (i = 0; i < nbufs; off += bufs[i++].iov_len) { |
|
acb[i] = malloc(sizeof(struct aiocb)); |
|
if (!acb[i]) { |
|
LOGERR; |
|
for (i = 0; i < nbufs; i++) |
|
if (acb[i]) |
|
free(acb[i]); |
|
free(acb); |
|
return NULL; |
|
} else |
|
memset(acb[i], 0, sizeof(struct aiocb)); |
|
acb[i]->aio_fildes = fd; |
|
acb[i]->aio_nbytes = bufs[i].iov_len; |
|
acb[i]->aio_buf = bufs[i].iov_base; |
|
acb[i]->aio_offset = off; |
|
acb[i]->aio_lio_opcode = LIO_WRITE; |
|
} |
|
memset(&sig, 0, sizeof sig); |
|
sig.sigev_notify = SIGEV_KEVENT; |
|
sig.sigev_notify_kqueue = root->root_kq; |
|
sig.sigev_value.sival_ptr = acb; |
|
|
|
if (lio_listio(LIO_NOWAIT, acb, nbufs, &sig)) { |
|
LOGERR; |
|
for (i = 0; i < nbufs; i++) |
|
if (acb[i]) |
|
free(acb[i]); |
|
free(acb); |
|
return NULL; |
|
} |
|
|
|
return schedLIO(root, func, arg, (void*) acb, bufs, nbufs); |
|
} |
|
#endif /* EVFILT_LIO */ |
|
#endif /* AIO_SUPPORT */ |
|
|
/* |
/* |
* schedTimer() - Add TIMER task to scheduler queue |
* schedTimer() - Add TIMER task to scheduler queue |