| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: t_sem.c,v 1.6 2012/03/07 23:31:44 joerg Exp $ */ | | 1 | /* $NetBSD: t_sem.c,v 1.7 2012/03/09 19:46:37 joerg Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 2008, 2010 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2008, 2010 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -76,27 +76,27 @@ | | | @@ -76,27 +76,27 @@ |
76 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 76 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
77 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 77 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
78 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR | | 78 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
79 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | | 79 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
80 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE | | 80 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
81 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, | | 81 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
82 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | | 82 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
83 | * | | 83 | * |
84 | ****************************************************************************/ | | 84 | ****************************************************************************/ |
85 | | | 85 | |
86 | #include <sys/cdefs.h> | | 86 | #include <sys/cdefs.h> |
87 | __COPYRIGHT("@(#) Copyright (c) 2008, 2010\ | | 87 | __COPYRIGHT("@(#) Copyright (c) 2008, 2010\ |
88 | The NetBSD Foundation, inc. All rights reserved."); | | 88 | The NetBSD Foundation, inc. All rights reserved."); |
89 | __RCSID("$NetBSD: t_sem.c,v 1.6 2012/03/07 23:31:44 joerg Exp $"); | | 89 | __RCSID("$NetBSD: t_sem.c,v 1.7 2012/03/09 19:46:37 joerg Exp $"); |
90 | | | 90 | |
91 | #include <errno.h> | | 91 | #include <errno.h> |
92 | #include <fcntl.h> | | 92 | #include <fcntl.h> |
93 | #include <pthread.h> | | 93 | #include <pthread.h> |
94 | #include <semaphore.h> | | 94 | #include <semaphore.h> |
95 | #include <signal.h> | | 95 | #include <signal.h> |
96 | #include <stdio.h> | | 96 | #include <stdio.h> |
97 | #include <stdlib.h> | | 97 | #include <stdlib.h> |
98 | #include <string.h> | | 98 | #include <string.h> |
99 | #include <unistd.h> | | 99 | #include <unistd.h> |
100 | | | 100 | |
101 | #include <atf-c.h> | | 101 | #include <atf-c.h> |
102 | #include <atf-c/config.h> | | 102 | #include <atf-c/config.h> |
| @@ -220,34 +220,37 @@ static void | | | @@ -220,34 +220,37 @@ static void |
220 | alarm_ms(const int ms) | | 220 | alarm_ms(const int ms) |
221 | { | | 221 | { |
222 | struct itimerval timer; | | 222 | struct itimerval timer; |
223 | timer.it_interval.tv_sec = 0; | | 223 | timer.it_interval.tv_sec = 0; |
224 | timer.it_interval.tv_usec = 0; | | 224 | timer.it_interval.tv_usec = 0; |
225 | timer.it_value.tv_sec = 0; | | 225 | timer.it_value.tv_sec = 0; |
226 | timer.it_value.tv_usec = ms * 1000; | | 226 | timer.it_value.tv_usec = ms * 1000; |
227 | ATF_REQUIRE(setitimer(ITIMER_REAL, &timer, NULL) == 0); | | 227 | ATF_REQUIRE(setitimer(ITIMER_REAL, &timer, NULL) == 0); |
228 | } | | 228 | } |
229 | | | 229 | |
230 | static void * | | 230 | static void * |
231 | threadfunc(void *arg) | | 231 | threadfunc(void *arg) |
232 | { | | 232 | { |
233 | int i; | | 233 | int i, ret; |
234 | | | 234 | |
235 | printf("Entering loop\n"); | | 235 | printf("Entering loop\n"); |
236 | for (i = 0; i < 500; ) { | | 236 | for (i = 0; i < 500; ) { |
237 | if ((i & 1) != 0) { | | 237 | if ((i & 1) != 0) { |
238 | ATF_REQUIRE(sem_wait(&sem) != -1); | | 238 | do { |
| | | 239 | ret = sem_wait(&sem); |
| | | 240 | } while (ret == -1 && errno == EINTR); |
| | | 241 | ATF_REQUIRE(ret == 0); |
239 | } else { | | 242 | } else { |
240 | const int ret = sem_trywait(&sem); | | 243 | ret = sem_trywait(&sem); |
241 | if (ret == -1) { | | 244 | if (ret == -1) { |
242 | ATF_REQUIRE(errno == EAGAIN); | | 245 | ATF_REQUIRE(errno == EAGAIN); |
243 | continue; | | 246 | continue; |
244 | } | | 247 | } |
245 | } | | 248 | } |
246 | printf("%s: %d\n", __func__, i); | | 249 | printf("%s: %d\n", __func__, i); |
247 | alarm_ms(5); | | 250 | alarm_ms(5); |
248 | i++; | | 251 | i++; |
249 | } | | 252 | } |
250 | | | 253 | |
251 | return NULL; | | 254 | return NULL; |
252 | } | | 255 | } |
253 | | | 256 | |