Deleted Added
full compact
aio.c (156136) aio.c (156194)
1/*
2 * Copyright (c) 2005 David Xu <davidxu@freebsd.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *
1/*
2 * Copyright (c) 2005 David Xu <davidxu@freebsd.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *
26 * $FreeBSD: head/lib/librt/aio.c 156136 2006-03-01 06:37:34Z davidxu $
26 * $FreeBSD: head/lib/librt/aio.c 156194 2006-03-01 23:41:47Z davidxu $
27 *
28 */
29
30#include <sys/cdefs.h>
31#include <sys/types.h>
32#include <sys/syscall.h>
33#include <sys/aio.h>
34

--- 31 unchanged lines hidden (view full) ---

66 f(sn->sn_value, (struct aiocb *)sn->sn_id);
67}
68
69static int
70aio_io(struct aiocb *iocb, int (*sysfunc)(struct aiocb *iocb))
71{
72 struct sigev_node *sn;
73 struct sigevent saved_ev;
27 *
28 */
29
30#include <sys/cdefs.h>
31#include <sys/types.h>
32#include <sys/syscall.h>
33#include <sys/aio.h>
34

--- 31 unchanged lines hidden (view full) ---

66 f(sn->sn_value, (struct aiocb *)sn->sn_id);
67}
68
69static int
70aio_io(struct aiocb *iocb, int (*sysfunc)(struct aiocb *iocb))
71{
72 struct sigev_node *sn;
73 struct sigevent saved_ev;
74 int ret;
74 int ret, err;
75
76 if (iocb->aio_sigevent.sigev_notify != SIGEV_THREAD) {
77 ret = sysfunc(iocb);
78 return (ret);
79 }
80
81 if (__sigev_check_init()) {
82 /* This might be that thread library is not enabled. */

--- 16 unchanged lines hidden (view full) ---

99 __sigev_register(sn);
100 __sigev_list_unlock();
101
102 sn->sn_dispatch = aio_dispatch;
103 ret = sysfunc(iocb);
104 iocb->aio_sigevent = saved_ev;
105
106 if (ret != 0) {
75
76 if (iocb->aio_sigevent.sigev_notify != SIGEV_THREAD) {
77 ret = sysfunc(iocb);
78 return (ret);
79 }
80
81 if (__sigev_check_init()) {
82 /* This might be that thread library is not enabled. */

--- 16 unchanged lines hidden (view full) ---

99 __sigev_register(sn);
100 __sigev_list_unlock();
101
102 sn->sn_dispatch = aio_dispatch;
103 ret = sysfunc(iocb);
104 iocb->aio_sigevent = saved_ev;
105
106 if (ret != 0) {
107 err = errno;
107 __sigev_list_lock();
108 __sigev_delete_node(sn);
109 __sigev_list_unlock();
108 __sigev_list_lock();
109 __sigev_delete_node(sn);
110 __sigev_list_unlock();
111 errno = err;
110 }
111 return (ret);
112}
113
114int
115__aio_read(struct aiocb *iocb)
116{
112 }
113 return (ret);
114}
115
116int
117__aio_read(struct aiocb *iocb)
118{
119
117 return aio_io(iocb, &__sys_aio_read);
118}
119
120int
121__aio_write(struct aiocb *iocb)
122{
120 return aio_io(iocb, &__sys_aio_read);
121}
122
123int
124__aio_write(struct aiocb *iocb)
125{
126
123 return aio_io(iocb, &__sys_aio_write);
124}
125
126int
127__aio_waitcomplete(struct aiocb **iocbp, struct timespec *timeout)
128{
127 return aio_io(iocb, &__sys_aio_write);
128}
129
130int
131__aio_waitcomplete(struct aiocb **iocbp, struct timespec *timeout)
132{
133 int err;
129 int ret = __sys_aio_waitcomplete(iocbp, timeout);
130
131 if (*iocbp) {
132 if ((*iocbp)->aio_sigevent.sigev_notify == SIGEV_THREAD) {
134 int ret = __sys_aio_waitcomplete(iocbp, timeout);
135
136 if (*iocbp) {
137 if ((*iocbp)->aio_sigevent.sigev_notify == SIGEV_THREAD) {
138 err = errno;
133 __sigev_list_lock();
134 __sigev_delete(SI_ASYNCIO, (sigev_id_t)(*iocbp));
135 __sigev_list_unlock();
139 __sigev_list_lock();
140 __sigev_delete(SI_ASYNCIO, (sigev_id_t)(*iocbp));
141 __sigev_list_unlock();
142 errno = err;
136 }
137 }
138
139 return (ret);
140}
141
142int
143__aio_return(struct aiocb *iocb)
144{
143 }
144 }
145
146 return (ret);
147}
148
149int
150__aio_return(struct aiocb *iocb)
151{
145 int ret = __sys_aio_return(iocb);
146 int err = __sys_aio_error(iocb);
147
152
148 if (err != EINPROGRESS &&
149 iocb->aio_sigevent.sigev_notify == SIGEV_THREAD) {
153 if (iocb->aio_sigevent.sigev_notify == SIGEV_THREAD) {
154 if (__sys_aio_error(iocb) == EINPROGRESS)
155 return (EINPROGRESS);
150 __sigev_list_lock();
151 __sigev_delete(SI_ASYNCIO, (sigev_id_t)iocb);
152 __sigev_list_unlock();
153 }
154
156 __sigev_list_lock();
157 __sigev_delete(SI_ASYNCIO, (sigev_id_t)iocb);
158 __sigev_list_unlock();
159 }
160
155 return (ret);
161 return __sys_aio_return(iocb);
156}
162}