3 #include "pthread_impl.h"
5 static void dummy(void)
9 weak_alias(dummy, __aio_wake);
11 static void notify_signal(struct sigevent *sev)
14 .si_signo = sev->sigev_signo,
15 .si_value = sev->sigev_value,
16 .si_code = SI_ASYNCIO,
17 .si_pid = __pthread_self()->pid,
20 __syscall(SYS_rt_sigqueueinfo, si.si_pid, si.si_signo, &si);
23 static void *io_thread(void *p)
26 int fd = cb->aio_fildes;
27 void *buf = (void *)cb->aio_buf;
28 size_t len = cb->aio_nbytes;
29 off_t off = cb->aio_offset;
30 int op = cb->aio_lio_opcode;
31 struct sigevent sev = cb->aio_sigevent;
34 if (op == LIO_WRITE) {
35 if ( (fcntl(fd, F_GETFL) & O_APPEND)
36 ||((ret = pwrite(fd, buf, len, off))<0 && errno==ESPIPE) )
37 ret = write(fd, buf, len);
38 } else if (op == LIO_READ) {
39 if ( (ret = pread(fd, buf, len, off))<0 && errno==ESPIPE )
40 ret = read(fd, buf, len);
46 if (ret < 0) a_store(&cb->__err, errno);
47 else a_store(&cb->__err, 0);
51 switch (cb->aio_sigevent.sigev_notify) {
56 sev.sigev_notify_function(sev.sigev_value);
63 static int new_req(struct aiocb *cb)
70 if (cb->aio_sigevent.sigev_notify == SIGEV_THREAD) {
71 if (cb->aio_sigevent.sigev_notify_attributes)
72 a = *cb->aio_sigevent.sigev_notify_attributes;
74 pthread_attr_init(&a);
76 pthread_attr_init(&a);
77 pthread_attr_setstacksize(&a, PAGE_SIZE);
78 pthread_attr_setguardsize(&a, 0);
80 pthread_attr_setdetachstate(&a, PTHREAD_CREATE_DETACHED);
82 pthread_sigmask(SIG_BLOCK, &set, &set);
83 cb->__err = EINPROGRESS;
84 if (pthread_create(&td, &a, io_thread, cb)) {
88 pthread_sigmask(SIG_SETMASK, &set, 0);
94 int aio_read(struct aiocb *cb)
96 cb->aio_lio_opcode = LIO_READ;
100 int aio_write(struct aiocb *cb)
102 cb->aio_lio_opcode = LIO_WRITE;