Back to index

glibc  2.9
tst-rwlock3.c
Go to the documentation of this file.
00001 /* Copyright (C) 2002 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003    Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 /* This test case checks more than standard compliance.  An
00021    implementation may provide this service but it is not required to
00022    do so.  */
00023 
00024 #include <errno.h>
00025 #include <pthread.h>
00026 #include <stdio.h>
00027 
00028 
00029 static int
00030 do_test (void)
00031 {
00032   pthread_rwlock_t r;
00033   int e;
00034 
00035   if (pthread_rwlock_init (&r, NULL) != 0)
00036     {
00037       puts ("rwlock_init failed");
00038       return 1;
00039     }
00040   puts ("rwlock_init succeeded");
00041 
00042   if (pthread_rwlock_trywrlock (&r) != 0)
00043     {
00044       puts ("rwlock_trywrlock on unlocked rwlock failed");
00045       return 1;
00046     }
00047   puts ("rwlock_trywrlock on unlocked rwlock succeeded");
00048 
00049   e = pthread_rwlock_rdlock (&r);
00050   if (e == 0)
00051     {
00052       puts ("rwlock_rdlock on rwlock with writer succeeded");
00053       return 1;
00054     }
00055   if (e != EDEADLK)
00056     {
00057       puts ("rwlock_rdlock on rwlock with writer failed != EDEADLK");
00058       return 1;
00059     }
00060   puts ("rwlock_rdlock on rwlock with writer failed with EDEADLK");
00061 
00062   e = pthread_rwlock_wrlock (&r);
00063   if (e == 0)
00064     {
00065       puts ("rwlock_wrlock on rwlock with writer succeeded");
00066       return 1;
00067     }
00068   if (e != EDEADLK)
00069     {
00070       puts ("rwlock_wrlock on rwlock with writer failed != EDEADLK");
00071       return 1;
00072     }
00073   puts ("rwlock_wrlock on rwlock with writer failed with EDEADLK");
00074 
00075   if (pthread_rwlock_unlock (&r) != 0)
00076     {
00077       puts ("rwlock_unlock failed");
00078       return 1;
00079     }
00080   puts ("rwlock_unlock succeeded");
00081 
00082   if (pthread_rwlock_destroy (&r) != 0)
00083     {
00084       puts ("rwlock_destroy failed");
00085       return 1;
00086     }
00087   puts ("rwlock_destroy succeeded");
00088 
00089   return 0;
00090 }
00091 
00092 #define TEST_FUNCTION do_test ()
00093 #include "../test-skeleton.c"