5 #include "pthread_impl.h"
13 static int lio_wait(struct lio_state *st)
15 int i, err, got_err = 0;
17 struct aiocb **cbs = st->cbs;
20 for (i=0; i<cnt; i++) {
21 if (!cbs[i]) continue;
22 err = aio_error(cbs[i]);
35 if (aio_suspend((void *)cbs, cnt, 0))
40 static void notify_signal(struct sigevent *sev)
43 .si_signo = sev->sigev_signo,
44 .si_value = sev->sigev_value,
45 .si_code = SI_ASYNCIO,
49 __syscall(SYS_rt_sigqueueinfo, si.si_pid, si.si_signo, &si);
52 static void *wait_thread(void *p)
54 struct lio_state *st = p;
55 struct sigevent *sev = st->sev;
58 switch (sev->sigev_notify) {
63 sev->sigev_notify_function(sev->sigev_value);
69 int lio_listio(int mode, struct aiocb *restrict const *restrict cbs, int cnt, struct sigevent *restrict sev)
72 struct lio_state *st=0;
79 if (mode == LIO_WAIT || (sev && sev->sigev_notify != SIGEV_NONE)) {
80 if (!(st = malloc(sizeof *st + cnt*sizeof *cbs))) {
86 memcpy(st->cbs, (void*) cbs, cnt*sizeof *cbs);
89 for (i=0; i<cnt; i++) {
90 if (!cbs[i]) continue;
91 switch (cbs[i]->aio_lio_opcode) {
93 ret = aio_read(cbs[i]);
96 ret = aio_write(cbs[i]);
108 if (mode == LIO_WAIT) {
116 sigset_t set, set_old;
119 if (sev->sigev_notify == SIGEV_THREAD) {
120 if (sev->sigev_notify_attributes)
121 a = *sev->sigev_notify_attributes;
123 pthread_attr_init(&a);
125 pthread_attr_init(&a);
126 pthread_attr_setstacksize(&a, PAGE_SIZE);
127 pthread_attr_setguardsize(&a, 0);
129 pthread_attr_setdetachstate(&a, PTHREAD_CREATE_DETACHED);
131 pthread_sigmask(SIG_BLOCK, &set, &set_old);
132 if (pthread_create(&td, &a, wait_thread, st)) {
137 pthread_sigmask(SIG_SETMASK, &set_old, 0);
143 weak_alias(lio_listio, lio_listio64);