3 #include "pthread_impl.h"
11 static int lio_wait(struct lio_state *st)
15 struct aiocb **cbs = st->cbs;
18 for (i=0; i<cnt; i++) {
19 if (!cbs[i]) continue;
20 err = aio_error(cbs[i]);
33 if (aio_suspend((void *)cbs, cnt, 0))
38 static void notify_signal(struct sigevent *sev)
41 .si_signo = sev->sigev_signo,
42 .si_value = sev->sigev_value,
43 .si_code = SI_ASYNCIO,
44 .si_pid = __pthread_self()->pid,
47 __syscall(SYS_rt_sigqueueinfo, si.si_pid, si.si_signo, &si);
50 static void *wait_thread(void *p)
52 struct lio_state *st = p;
53 struct sigevent *sev = st->sev;
56 switch (sev->sigev_notify) {
61 sev->sigev_notify_function(sev->sigev_value);
67 int lio_listio(int mode, struct aiocb *const cbs[], int cnt, struct sigevent *sev)
70 struct lio_state *st=0;
77 if (mode == LIO_WAIT || (sev && sev->sigev_notify != SIGEV_NONE)) {
78 if (!(st = malloc(sizeof *st + cnt*sizeof *cbs))) {
84 memcpy(st->cbs, cbs, cnt*sizeof *cbs);
87 for (i=0; i<cnt; i++) {
88 if (!cbs[i]) continue;
89 switch (cbs[i]->aio_lio_opcode) {
91 ret = aio_read(cbs[i]);
94 ret = aio_write(cbs[i]);
106 if (mode == LIO_WAIT) {
117 if (sev->sigev_notify == SIGEV_THREAD) {
118 if (sev->sigev_notify_attributes)
119 a = *sev->sigev_notify_attributes;
121 pthread_attr_init(&a);
123 pthread_attr_init(&a);
124 pthread_attr_setstacksize(&a, PAGE_SIZE);
125 pthread_attr_setguardsize(&a, 0);
127 pthread_attr_setdetachstate(&a, PTHREAD_CREATE_DETACHED);
129 pthread_sigmask(SIG_BLOCK, &set, &set);
130 if (pthread_create(&td, &a, wait_thread, st)) {
135 pthread_sigmask(SIG_SETMASK, &set, 0);