Expand PMF_FN_* macros.
[netbsd-mini2440.git] / regress / lib / libpthread / rwlock1 / rwlock1.c
blob3fc4474e7971281eb8db1fa78aad806c0c20b22d
1 /* $NetBSD: rwlock1.c,v 1.1 2004/08/03 11:36:23 yamt Exp $ */
3 /*-
4 * Copyright (c)2004 YAMAMOTO Takashi,
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
29 #include <err.h>
30 #include <errno.h>
31 #include <pthread.h>
32 #include <stdlib.h>
34 pthread_rwlock_t lk;
36 int main(void);
37 void *do_nothing(void *);
39 struct timespec to;
41 /* ARGSUSED */
42 void *
43 do_nothing(void *dummy)
46 return NULL;
49 int
50 main()
52 int error;
53 pthread_t t;
55 error = pthread_create(&t, NULL, do_nothing, NULL);
56 if (error)
57 exit(1000);
59 error = pthread_rwlock_init(&lk, NULL);
60 if (error)
61 exit(1);
63 error = pthread_rwlock_rdlock(&lk);
64 if (error)
65 exit(2);
67 error = pthread_rwlock_rdlock(&lk);
68 if (error)
69 exit(3);
71 error = pthread_rwlock_unlock(&lk);
72 if (error)
73 exit(4);
75 error = pthread_rwlock_trywrlock(&lk);
76 if (error != EBUSY)
77 exit(5);
79 if (clock_gettime(CLOCK_REALTIME, &to))
80 err(101, "clock_gettime");
81 to.tv_sec++;
82 error = pthread_rwlock_timedwrlock(&lk, &to);
83 if (error != ETIMEDOUT && error != EDEADLK)
84 exit(6);
86 error = pthread_rwlock_unlock(&lk);
87 if (error)
88 exit(7);
90 if (clock_gettime(CLOCK_REALTIME, &to))
91 err(102, "clock_gettime");
92 to.tv_sec++;
93 error = pthread_rwlock_timedwrlock(&lk, &to);
94 if (error)
95 exit(8);
97 if (clock_gettime(CLOCK_REALTIME, &to))
98 err(103, "clock_gettime");
99 to.tv_sec++;
100 error = pthread_rwlock_timedwrlock(&lk, &to);
101 if (error != ETIMEDOUT && error != EDEADLK)
102 exit(9);
104 exit(0);
106 /* NOTREACHED */