5 #include "pthread_impl.h"
14 static int lio_wait(struct lio_state *st)
16 int i, err, got_err = 0;
18 struct aiocb **cbs = st->cbs;
21 for (i=0; i<cnt; i++) {
22 if (!cbs[i]) continue;
23 err = aio_error(cbs[i]);
36 if (aio_suspend((void *)cbs, cnt, 0))
41 static void notify_signal(struct sigevent *sev)
44 .si_signo = sev->sigev_signo,
45 .si_value = sev->sigev_value,
46 .si_code = SI_ASYNCIO,
47 .si_pid = __pthread_self()->pid,
50 __syscall(SYS_rt_sigqueueinfo, si.si_pid, si.si_signo, &si);
53 static void *wait_thread(void *p)
55 struct lio_state *st = p;
56 struct sigevent *sev = st->sev;
59 switch (sev->sigev_notify) {
64 sev->sigev_notify_function(sev->sigev_value);
70 int lio_listio(int mode, struct aiocb *restrict const *restrict cbs, int cnt, struct sigevent *restrict sev)
73 struct lio_state *st=0;
80 if (mode == LIO_WAIT || (sev && sev->sigev_notify != SIGEV_NONE)) {
81 if (!(st = malloc(sizeof *st + cnt*sizeof *cbs))) {
87 memcpy(st->cbs, (void*) cbs, cnt*sizeof *cbs);
90 for (i=0; i<cnt; i++) {
91 if (!cbs[i]) continue;
92 switch (cbs[i]->aio_lio_opcode) {
94 ret = aio_read(cbs[i]);
97 ret = aio_write(cbs[i]);
109 if (mode == LIO_WAIT) {
120 if (sev->sigev_notify == SIGEV_THREAD) {
121 if (sev->sigev_notify_attributes)
122 a = *sev->sigev_notify_attributes;
124 pthread_attr_init(&a);
126 pthread_attr_init(&a);
127 pthread_attr_setstacksize(&a, PAGE_SIZE);
128 pthread_attr_setguardsize(&a, 0);
130 pthread_attr_setdetachstate(&a, PTHREAD_CREATE_DETACHED);
132 pthread_sigmask(SIG_BLOCK, &set, &set);
133 if (pthread_create(&td, &a, wait_thread, st)) {
138 pthread_sigmask(SIG_SETMASK, &set, 0);