xref: /dragonfly/test/testcases/posixipc/wait_unlocked/wait_unlocked.c (revision 0bba68feaae2960c1f2b5feb6978a8918f571707)
1 #include <common.h>
2 
3 int
main(void)4 main(void) {
5           sem_t id;
6           u_int elapsed;
7 
8           if (sem_init(&id, 0, 1) < 0) {
9                     perror("sem_init");
10                     return 1;
11           }
12 
13           /* This should succeed right away and set the value to 0. */
14           if (testwait(&id, &elapsed) < 0) {
15                     sem_destroy(&id);
16                     return 1;
17           }
18           if (!ELAPSED(elapsed, 0)) {
19                     fprintf(stderr, "sem_wait() of unlocked sem took %ums",
20                         elapsed);
21                     sem_destroy(&id);
22                     return 1;
23           }
24           if (checkvalue(&id, 0) < 0) {
25                     sem_destroy(&id);
26                     return 1;
27           }
28 
29           if (sem_destroy(&id) < 0) {
30                     perror("sem_destroy");
31                     return 1;
32           }
33           return 0;
34 }
35