diff options
| author | yamt <yamt@NetBSD.org> | 2004-08-03 11:36:23 +0000 |
|---|---|---|
| committer | yamt <yamt@NetBSD.org> | 2004-08-03 11:36:23 +0000 |
| commit | bb73a3ff4ce014c467ad8bb4f094ad7cd06e7202 (patch) | |
| tree | c6baa0deb240a79889636bb95b97e293f3f1eaa9 | |
| parent | 8c0706bddd57e19ea21243557432473f17cd4684 (diff) | |
add a test for rwlock.
| -rw-r--r-- | regress/lib/libpthread/Makefile | 4 | ||||
| -rw-r--r-- | regress/lib/libpthread/rwlock1/Makefile | 15 | ||||
| -rw-r--r-- | regress/lib/libpthread/rwlock1/rwlock1.c | 86 |
3 files changed, 103 insertions, 2 deletions
diff --git a/regress/lib/libpthread/Makefile b/regress/lib/libpthread/Makefile index 534ad6a0fd4..3bdc4c8f471 100644 --- a/regress/lib/libpthread/Makefile +++ b/regress/lib/libpthread/Makefile @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.21 2004/07/27 22:01:51 yamt Exp $ +# $NetBSD: Makefile,v 1.22 2004/08/03 11:36:23 yamt Exp $ .include <bsd.own.mk> @@ -17,7 +17,7 @@ ARCHSUBDIR= ${MACHINE_CPU} SUBDIR+= atexit barrier1 cancel2 cond1 cond2 cond3 cond4 cond5 condcancel1 \ conddestroy1 exit1 fork kill1 mutex1 mutex2 mutex3 mutex4 name \ - once1 once2 preempt1 resolv sem sigalarm sigmask1 siglongjmp1 \ + once1 once2 preempt1 resolv rwlock1 sem sigalarm sigmask1 siglongjmp1 \ sigsuspend .endif diff --git a/regress/lib/libpthread/rwlock1/Makefile b/regress/lib/libpthread/rwlock1/Makefile new file mode 100644 index 00000000000..ff8033564a9 --- /dev/null +++ b/regress/lib/libpthread/rwlock1/Makefile @@ -0,0 +1,15 @@ +# $NetBSD: Makefile,v 1.1 2004/08/03 11:36:23 yamt Exp $ + +WARNS=3 + +PROG= rwlock1 +SRCS= rwlock1.c + +LDADD= -lpthread + +NOMAN= + +regress: + ./rwlock1 + +.include <bsd.prog.mk> diff --git a/regress/lib/libpthread/rwlock1/rwlock1.c b/regress/lib/libpthread/rwlock1/rwlock1.c new file mode 100644 index 00000000000..d9b3696587e --- /dev/null +++ b/regress/lib/libpthread/rwlock1/rwlock1.c @@ -0,0 +1,86 @@ +/* $NetBSD: rwlock1.c,v 1.1 2004/08/03 11:36:23 yamt Exp $ */ + +/*- + * Copyright (c)2004 YAMAMOTO Takashi, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <errno.h> +#include <pthread.h> +#include <stdlib.h> +#include <stdio.h> + +pthread_rwlock_t lk; + +int main(void); +void *do_nothing(void *); + +struct timespec to = {1, 0}; + +/* ARGSUSED */ +void * +do_nothing(void *dummy) +{ + + return NULL; +} + +int +main() +{ + int error; + pthread_t t; + + error = pthread_create(&t, NULL, do_nothing, NULL); + if (error) + exit(7); + + error = pthread_rwlock_init(&lk, NULL); + if (error) + exit(1); + + error = pthread_rwlock_rdlock(&lk); + if (error) + exit(2); + + error = pthread_rwlock_rdlock(&lk); + if (error) + exit(3); + + error = pthread_rwlock_unlock(&lk); + if (error) + exit(4); + + error = pthread_rwlock_trywrlock(&lk); + if (error != EBUSY) + exit(5); + + error = pthread_rwlock_timedwrlock(&lk, &to); + if (error != ETIMEDOUT && error != EDEADLK) + exit(6); + + exit(0); + + /* NOTREACHED */ +} |
