Make rumpuser_cv_timedwait take two int64's instead timespec to uncouple it from the timespec layout. Also, change return value to zero for "timeout didn't expire" and non-zero for "timeout expired". This decouples the interface from errno assignments.diff -r1.31 -r1.32 src/sys/rump/include/rump/rumpuser.h
(pooka)
--- src/sys/rump/include/rump/rumpuser.h 2009/10/24 11:36:59 1.31
+++ src/sys/rump/include/rump/rumpuser.h 2009/11/11 16:46:50 1.32
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: rumpuser.h,v 1.31 2009/10/24 11:36:59 pooka Exp $ */ | 1 | /* $NetBSD: rumpuser.h,v 1.32 2009/11/11 16:46:50 pooka Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 2007 Antti Kantee. All Rights Reserved. | 4 | * Copyright (c) 2007 Antti Kantee. All Rights Reserved. | |
5 | * | 5 | * | |
6 | * Development of this software was supported by Google Summer of Code. | 6 | * Development of this software was supported by Google Summer of Code. | |
7 | * | 7 | * | |
8 | * Redistribution and use in source and binary forms, with or without | 8 | * Redistribution and use in source and binary forms, with or without | |
9 | * modification, are permitted provided that the following conditions | 9 | * modification, are permitted provided that the following conditions | |
10 | * are met: | 10 | * are met: | |
11 | * 1. Redistributions of source code must retain the above copyright | 11 | * 1. Redistributions of source code must retain the above copyright | |
12 | * notice, this list of conditions and the following disclaimer. | 12 | * notice, this list of conditions and the following disclaimer. | |
13 | * 2. Redistributions in binary form must reproduce the above copyright | 13 | * 2. Redistributions in binary form must reproduce the above copyright | |
14 | * notice, this list of conditions and the following disclaimer in the | 14 | * notice, this list of conditions and the following disclaimer in the | |
@@ -132,27 +132,27 @@ int rumpuser_rw_tryenter(struct rumpuse | @@ -132,27 +132,27 @@ int rumpuser_rw_tryenter(struct rumpuse | |||
132 | void rumpuser_rw_exit(struct rumpuser_rw *); | 132 | void rumpuser_rw_exit(struct rumpuser_rw *); | |
133 | void rumpuser_rw_destroy(struct rumpuser_rw *); | 133 | void rumpuser_rw_destroy(struct rumpuser_rw *); | |
134 | int rumpuser_rw_held(struct rumpuser_rw *); | 134 | int rumpuser_rw_held(struct rumpuser_rw *); | |
135 | int rumpuser_rw_rdheld(struct rumpuser_rw *); | 135 | int rumpuser_rw_rdheld(struct rumpuser_rw *); | |
136 | int rumpuser_rw_wrheld(struct rumpuser_rw *); | 136 | int rumpuser_rw_wrheld(struct rumpuser_rw *); | |
137 | 137 | |||
138 | struct rumpuser_cv; | 138 | struct rumpuser_cv; | |
139 | 139 | |||
140 | void rumpuser_cv_init(struct rumpuser_cv **); | 140 | void rumpuser_cv_init(struct rumpuser_cv **); | |
141 | void rumpuser_cv_destroy(struct rumpuser_cv *); | 141 | void rumpuser_cv_destroy(struct rumpuser_cv *); | |
142 | void rumpuser_cv_wait(struct rumpuser_cv *, struct rumpuser_mtx *); | 142 | void rumpuser_cv_wait(struct rumpuser_cv *, struct rumpuser_mtx *); | |
143 | void rumpuser_cv_wait_nowrap(struct rumpuser_cv *, struct rumpuser_mtx *); | 143 | void rumpuser_cv_wait_nowrap(struct rumpuser_cv *, struct rumpuser_mtx *); | |
144 | int rumpuser_cv_timedwait(struct rumpuser_cv *, struct rumpuser_mtx *, | 144 | int rumpuser_cv_timedwait(struct rumpuser_cv *, struct rumpuser_mtx *, | |
145 | struct timespec *); | 145 | int64_t, int64_t); | |
146 | void rumpuser_cv_signal(struct rumpuser_cv *); | 146 | void rumpuser_cv_signal(struct rumpuser_cv *); | |
147 | void rumpuser_cv_broadcast(struct rumpuser_cv *); | 147 | void rumpuser_cv_broadcast(struct rumpuser_cv *); | |
148 | int rumpuser_cv_has_waiters(struct rumpuser_cv *); | 148 | int rumpuser_cv_has_waiters(struct rumpuser_cv *); | |
149 | 149 | |||
150 | struct lwp; | 150 | struct lwp; | |
151 | 151 | |||
152 | void rumpuser_set_curlwp(struct lwp *); | 152 | void rumpuser_set_curlwp(struct lwp *); | |
153 | struct lwp *rumpuser_get_curlwp(void); | 153 | struct lwp *rumpuser_get_curlwp(void); | |
154 | 154 | |||
155 | /* "aio" stuff for being able to fire of a B_ASYNC I/O and continue */ | 155 | /* "aio" stuff for being able to fire of a B_ASYNC I/O and continue */ | |
156 | struct rumpuser_aio { | 156 | struct rumpuser_aio { | |
157 | int rua_fd; | 157 | int rua_fd; | |
158 | uint8_t *rua_data; | 158 | uint8_t *rua_data; |
--- src/sys/rump/librump/rumpkern/intr.c 2009/11/09 19:16:18 1.20
+++ src/sys/rump/librump/rumpkern/intr.c 2009/11/11 16:46:50 1.21
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: intr.c,v 1.20 2009/11/09 19:16:18 pooka Exp $ */ | 1 | /* $NetBSD: intr.c,v 1.21 2009/11/11 16:46:50 pooka Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 2008 Antti Kantee. All Rights Reserved. | 4 | * Copyright (c) 2008 Antti Kantee. All Rights Reserved. | |
5 | * | 5 | * | |
6 | * Redistribution and use in source and binary forms, with or without | 6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions | 7 | * modification, are permitted provided that the following conditions | |
8 | * are met: | 8 | * are met: | |
9 | * 1. Redistributions of source code must retain the above copyright | 9 | * 1. Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | 10 | * notice, this list of conditions and the following disclaimer. | |
11 | * 2. Redistributions in binary form must reproduce the above copyright | 11 | * 2. Redistributions in binary form must reproduce the above copyright | |
12 | * notice, this list of conditions and the following disclaimer in the | 12 | * notice, this list of conditions and the following disclaimer in the | |
13 | * documentation and/or other materials provided with the distribution. | 13 | * documentation and/or other materials provided with the distribution. | |
14 | * | 14 | * | |
@@ -16,27 +16,27 @@ | @@ -16,27 +16,27 @@ | |||
16 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 16 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
18 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | 18 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | |
19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
25 | * SUCH DAMAGE. | 25 | * SUCH DAMAGE. | |
26 | */ | 26 | */ | |
27 | 27 | |||
28 | #include <sys/cdefs.h> | 28 | #include <sys/cdefs.h> | |
29 | __KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.20 2009/11/09 19:16:18 pooka Exp $"); | 29 | __KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.21 2009/11/11 16:46:50 pooka Exp $"); | |
30 | 30 | |||
31 | #include <sys/param.h> | 31 | #include <sys/param.h> | |
32 | #include <sys/cpu.h> | 32 | #include <sys/cpu.h> | |
33 | #include <sys/kmem.h> | 33 | #include <sys/kmem.h> | |
34 | #include <sys/kthread.h> | 34 | #include <sys/kthread.h> | |
35 | #include <sys/intr.h> | 35 | #include <sys/intr.h> | |
36 | 36 | |||
37 | #include <rump/rumpuser.h> | 37 | #include <rump/rumpuser.h> | |
38 | 38 | |||
39 | #include "rump_private.h" | 39 | #include "rump_private.h" | |
40 | 40 | |||
41 | /* | 41 | /* | |
42 | * Interrupt simulator. It executes hardclock() and softintrs. | 42 | * Interrupt simulator. It executes hardclock() and softintrs. | |
@@ -114,27 +114,27 @@ doclock(void *noarg) | @@ -114,27 +114,27 @@ doclock(void *noarg) | |||
114 | rumpuser_mutex_enter(clockmtx); | 114 | rumpuser_mutex_enter(clockmtx); | |
115 | rumpuser_cv_signal(clockcv); | 115 | rumpuser_cv_signal(clockcv); | |
116 | 116 | |||
117 | for (;;) { | 117 | for (;;) { | |
118 | callout_hardclock(); | 118 | callout_hardclock(); | |
119 | 119 | |||
120 | if (++ticks == hz) { | 120 | if (++ticks == hz) { | |
121 | time_uptime++; | 121 | time_uptime++; | |
122 | ticks = 0; | 122 | ticks = 0; | |
123 | } | 123 | } | |
124 | 124 | |||
125 | /* wait until the next tick. XXX: what if the clock changes? */ | 125 | /* wait until the next tick. XXX: what if the clock changes? */ | |
126 | while (rumpuser_cv_timedwait(clockcv, clockmtx, | 126 | while (rumpuser_cv_timedwait(clockcv, clockmtx, | |
127 | &curtime) != EWOULDBLOCK) | 127 | curtime.tv_sec, curtime.tv_nsec) == 0) | |
128 | continue; | 128 | continue; | |
129 | 129 | |||
130 | clkgen++; | 130 | clkgen++; | |
131 | timespecadd(&clockup, &tick, &clockup); | 131 | timespecadd(&clockup, &tick, &clockup); | |
132 | clkgen++; | 132 | clkgen++; | |
133 | timespecadd(&clockup, &clockbase, &curtime); | 133 | timespecadd(&clockup, &clockbase, &curtime); | |
134 | } | 134 | } | |
135 | } | 135 | } | |
136 | 136 | |||
137 | /* | 137 | /* | |
138 | * Soft interrupt execution thread. Note that we run without a CPU | 138 | * Soft interrupt execution thread. Note that we run without a CPU | |
139 | * context until we start processing the interrupt. This is to avoid | 139 | * context until we start processing the interrupt. This is to avoid | |
140 | * lock recursion. | 140 | * lock recursion. |
--- src/sys/rump/librump/rumpkern/locks.c 2009/11/04 13:32:39 1.33
+++ src/sys/rump/librump/rumpkern/locks.c 2009/11/11 16:46:50 1.34
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: locks.c,v 1.33 2009/11/04 13:32:39 pooka Exp $ */ | 1 | /* $NetBSD: locks.c,v 1.34 2009/11/11 16:46:50 pooka Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 2007, 2008 Antti Kantee. All Rights Reserved. | 4 | * Copyright (c) 2007, 2008 Antti Kantee. All Rights Reserved. | |
5 | * | 5 | * | |
6 | * Development of this software was supported by the | 6 | * Development of this software was supported by the | |
7 | * Finnish Cultural Foundation. | 7 | * Finnish Cultural Foundation. | |
8 | * | 8 | * | |
9 | * Redistribution and use in source and binary forms, with or without | 9 | * Redistribution and use in source and binary forms, with or without | |
10 | * modification, are permitted provided that the following conditions | 10 | * modification, are permitted provided that the following conditions | |
11 | * are met: | 11 | * are met: | |
12 | * 1. Redistributions of source code must retain the above copyright | 12 | * 1. Redistributions of source code must retain the above copyright | |
13 | * notice, this list of conditions and the following disclaimer. | 13 | * notice, this list of conditions and the following disclaimer. | |
14 | * 2. Redistributions in binary form must reproduce the above copyright | 14 | * 2. Redistributions in binary form must reproduce the above copyright | |
@@ -19,27 +19,27 @@ | @@ -19,27 +19,27 @@ | |||
19 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 19 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
21 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | 21 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | |
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
28 | * SUCH DAMAGE. | 28 | * SUCH DAMAGE. | |
29 | */ | 29 | */ | |
30 | 30 | |||
31 | #include <sys/cdefs.h> | 31 | #include <sys/cdefs.h> | |
32 | __KERNEL_RCSID(0, "$NetBSD: locks.c,v 1.33 2009/11/04 13:32:39 pooka Exp $"); | 32 | __KERNEL_RCSID(0, "$NetBSD: locks.c,v 1.34 2009/11/11 16:46:50 pooka Exp $"); | |
33 | 33 | |||
34 | #include <sys/param.h> | 34 | #include <sys/param.h> | |
35 | #include <sys/kmem.h> | 35 | #include <sys/kmem.h> | |
36 | #include <sys/mutex.h> | 36 | #include <sys/mutex.h> | |
37 | #include <sys/rwlock.h> | 37 | #include <sys/rwlock.h> | |
38 | 38 | |||
39 | #include <rump/rumpuser.h> | 39 | #include <rump/rumpuser.h> | |
40 | 40 | |||
41 | #include "rump_private.h" | 41 | #include "rump_private.h" | |
42 | 42 | |||
43 | /* | 43 | /* | |
44 | * We map locks to pthread routines. The difference between kernel | 44 | * We map locks to pthread routines. The difference between kernel | |
45 | * and rumpuser routines is that while the kernel uses static | 45 | * and rumpuser routines is that while the kernel uses static | |
@@ -226,27 +226,31 @@ cv_timedwait(kcondvar_t *cv, kmutex_t *m | @@ -226,27 +226,31 @@ cv_timedwait(kcondvar_t *cv, kmutex_t *m | |||
226 | { | 226 | { | |
227 | struct timespec ts, tick; | 227 | struct timespec ts, tick; | |
228 | extern int hz; | 228 | extern int hz; | |
229 | 229 | |||
230 | nanotime(&ts); | 230 | nanotime(&ts); | |
231 | tick.tv_sec = ticks / hz; | 231 | tick.tv_sec = ticks / hz; | |
232 | tick.tv_nsec = (ticks % hz) * (1000000000/hz); | 232 | tick.tv_nsec = (ticks % hz) * (1000000000/hz); | |
233 | timespecadd(&ts, &tick, &ts); | 233 | timespecadd(&ts, &tick, &ts); | |
234 | 234 | |||
235 | if (ticks == 0) { | 235 | if (ticks == 0) { | |
236 | cv_wait(cv, mtx); | 236 | cv_wait(cv, mtx); | |
237 | return 0; | 237 | return 0; | |
238 | } else { | 238 | } else { | |
239 | return rumpuser_cv_timedwait(RUMPCV(cv), RUMPMTX(mtx), &ts); | 239 | if (rumpuser_cv_timedwait(RUMPCV(cv), RUMPMTX(mtx), | |
240 | ts.tv_sec, ts.tv_nsec)) | |||
241 | return EWOULDBLOCK; | |||
242 | else | |||
243 | return 0; | |||
240 | } | 244 | } | |
241 | } | 245 | } | |
242 | 246 | |||
243 | int | 247 | int | |
244 | cv_timedwait_sig(kcondvar_t *cv, kmutex_t *mtx, int ticks) | 248 | cv_timedwait_sig(kcondvar_t *cv, kmutex_t *mtx, int ticks) | |
245 | { | 249 | { | |
246 | 250 | |||
247 | return cv_timedwait(cv, mtx, ticks); | 251 | return cv_timedwait(cv, mtx, ticks); | |
248 | } | 252 | } | |
249 | 253 | |||
250 | void | 254 | void | |
251 | cv_signal(kcondvar_t *cv) | 255 | cv_signal(kcondvar_t *cv) | |
252 | { | 256 | { |
--- src/sys/rump/librump/rumpuser/Attic/rumpuser_pth.c 2009/11/09 18:00:26 1.37
+++ src/sys/rump/librump/rumpuser/Attic/rumpuser_pth.c 2009/11/11 16:46:50 1.38
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: rumpuser_pth.c,v 1.37 2009/11/09 18:00:26 pooka Exp $ */ | 1 | /* $NetBSD: rumpuser_pth.c,v 1.38 2009/11/11 16:46:50 pooka Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 2007 Antti Kantee. All Rights Reserved. | 4 | * Copyright (c) 2007 Antti Kantee. All Rights Reserved. | |
5 | * | 5 | * | |
6 | * Development of this software was supported by the | 6 | * Development of this software was supported by the | |
7 | * Finnish Cultural Foundation. | 7 | * Finnish Cultural Foundation. | |
8 | * | 8 | * | |
9 | * Redistribution and use in source and binary forms, with or without | 9 | * Redistribution and use in source and binary forms, with or without | |
10 | * modification, are permitted provided that the following conditions | 10 | * modification, are permitted provided that the following conditions | |
11 | * are met: | 11 | * are met: | |
12 | * 1. Redistributions of source code must retain the above copyright | 12 | * 1. Redistributions of source code must retain the above copyright | |
13 | * notice, this list of conditions and the following disclaimer. | 13 | * notice, this list of conditions and the following disclaimer. | |
14 | * 2. Redistributions in binary form must reproduce the above copyright | 14 | * 2. Redistributions in binary form must reproduce the above copyright | |
@@ -20,27 +20,27 @@ | @@ -20,27 +20,27 @@ | |||
20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
21 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | 21 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | |
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
28 | * SUCH DAMAGE. | 28 | * SUCH DAMAGE. | |
29 | */ | 29 | */ | |
30 | 30 | |||
31 | #include <sys/cdefs.h> | 31 | #include <sys/cdefs.h> | |
32 | #if !defined(lint) | 32 | #if !defined(lint) | |
33 | __RCSID("$NetBSD: rumpuser_pth.c,v 1.37 2009/11/09 18:00:26 pooka Exp $"); | 33 | __RCSID("$NetBSD: rumpuser_pth.c,v 1.38 2009/11/11 16:46:50 pooka Exp $"); | |
34 | #endif /* !lint */ | 34 | #endif /* !lint */ | |
35 | 35 | |||
36 | #ifdef __linux__ | 36 | #ifdef __linux__ | |
37 | #define _XOPEN_SOURCE 500 | 37 | #define _XOPEN_SOURCE 500 | |
38 | #define _BSD_SOURCE | 38 | #define _BSD_SOURCE | |
39 | #define _FILE_OFFSET_BITS 64 | 39 | #define _FILE_OFFSET_BITS 64 | |
40 | #endif | 40 | #endif | |
41 | 41 | |||
42 | #include <assert.h> | 42 | #include <assert.h> | |
43 | #include <errno.h> | 43 | #include <errno.h> | |
44 | #include <pthread.h> | 44 | #include <pthread.h> | |
45 | #include <stdlib.h> | 45 | #include <stdlib.h> | |
46 | #include <stdio.h> | 46 | #include <stdio.h> | |
@@ -463,41 +463,43 @@ void | @@ -463,41 +463,43 @@ void | |||
463 | rumpuser_cv_wait_nowrap(struct rumpuser_cv *cv, struct rumpuser_mtx *mtx) | 463 | rumpuser_cv_wait_nowrap(struct rumpuser_cv *cv, struct rumpuser_mtx *mtx) | |
464 | { | 464 | { | |
465 | 465 | |||
466 | cv->nwaiters++; | 466 | cv->nwaiters++; | |
467 | assert(mtx->recursion == 1); | 467 | assert(mtx->recursion == 1); | |
468 | mtxexit(mtx); | 468 | mtxexit(mtx); | |
469 | NOFAIL_ERRNO(pthread_cond_wait(&cv->pthcv, &mtx->pthmtx)); | 469 | NOFAIL_ERRNO(pthread_cond_wait(&cv->pthcv, &mtx->pthmtx)); | |
470 | mtxenter(mtx); | 470 | mtxenter(mtx); | |
471 | cv->nwaiters--; | 471 | cv->nwaiters--; | |
472 | } | 472 | } | |
473 | 473 | |||
474 | int | 474 | int | |
475 | rumpuser_cv_timedwait(struct rumpuser_cv *cv, struct rumpuser_mtx *mtx, | 475 | rumpuser_cv_timedwait(struct rumpuser_cv *cv, struct rumpuser_mtx *mtx, | |
476 | struct timespec *ts) | 476 | int64_t sec, int64_t nsec) | |
477 | { | 477 | { | |
478 | struct timespec ts; | |||
478 | int rv; | 479 | int rv; | |
479 | 480 | |||
481 | /* LINTED */ | |||
482 | ts.tv_sec = sec; ts.tv_nsec = nsec; | |||
483 | ||||
480 | cv->nwaiters++; | 484 | cv->nwaiters++; | |
481 | mtxexit(mtx); | 485 | mtxexit(mtx); | |
482 | KLOCK_WRAP(rv = pthread_cond_timedwait(&cv->pthcv, &mtx->pthmtx, ts)); | 486 | KLOCK_WRAP(rv = pthread_cond_timedwait(&cv->pthcv, &mtx->pthmtx, &ts)); | |
483 | mtxenter(mtx); | 487 | mtxenter(mtx); | |
484 | cv->nwaiters--; | 488 | cv->nwaiters--; | |
485 | if (rv != 0 && rv != ETIMEDOUT) | 489 | if (rv != 0 && rv != ETIMEDOUT) | |
486 | abort(); | 490 | abort(); | |
487 | 491 | |||
488 | if (rv == ETIMEDOUT) | 492 | return rv == ETIMEDOUT; | |
489 | rv = EWOULDBLOCK; | |||
490 | return rv; | |||
491 | } | 493 | } | |
492 | 494 | |||
493 | void | 495 | void | |
494 | rumpuser_cv_signal(struct rumpuser_cv *cv) | 496 | rumpuser_cv_signal(struct rumpuser_cv *cv) | |
495 | { | 497 | { | |
496 | 498 | |||
497 | NOFAIL_ERRNO(pthread_cond_signal(&cv->pthcv)); | 499 | NOFAIL_ERRNO(pthread_cond_signal(&cv->pthcv)); | |
498 | } | 500 | } | |
499 | 501 | |||
500 | void | 502 | void | |
501 | rumpuser_cv_broadcast(struct rumpuser_cv *cv) | 503 | rumpuser_cv_broadcast(struct rumpuser_cv *cv) | |
502 | { | 504 | { | |
503 | 505 |