Back to index

glibc  2.9
tst-rwlock1.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 #include <pthread.h>
00021 #include <stdio.h>
00022 
00023 
00024 static int
00025 do_test (void)
00026 {
00027   pthread_rwlock_t r;
00028 
00029   if (pthread_rwlock_init (&r, NULL) != 0)
00030     {
00031       puts ("rwlock_init failed");
00032       return 1;
00033     }
00034   puts ("rwlock_init succeeded");
00035 
00036   if (pthread_rwlock_rdlock (&r) != 0)
00037     {
00038       puts ("1st rwlock_rdlock failed");
00039       return 1;
00040     }
00041   puts ("1st rwlock_rdlock succeeded");
00042 
00043   if (pthread_rwlock_rdlock (&r) != 0)
00044     {
00045       puts ("2nd rwlock_rdlock failed");
00046       return 1;
00047     }
00048   puts ("2nd rwlock_rdlock succeeded");
00049 
00050   if (pthread_rwlock_unlock (&r) != 0)
00051     {
00052       puts ("1st rwlock_unlock failed");
00053       return 1;
00054     }
00055   puts ("1st rwlock_unlock succeeded");
00056 
00057   if (pthread_rwlock_unlock (&r) != 0)
00058     {
00059       puts ("2nd rwlock_unlock failed");
00060       return 1;
00061     }
00062   puts ("2nd rwlock_unlock succeeded");
00063 
00064   if (pthread_rwlock_wrlock (&r) != 0)
00065     {
00066       puts ("1st rwlock_wrlock failed");
00067       return 1;
00068     }
00069   puts ("1st rwlock_wrlock succeeded");
00070 
00071   if (pthread_rwlock_unlock (&r) != 0)
00072     {
00073       puts ("3rd rwlock_unlock failed");
00074       return 1;
00075     }
00076   puts ("3rd rwlock_unlock succeeded");
00077 
00078   if (pthread_rwlock_wrlock (&r) != 0)
00079     {
00080       puts ("2nd rwlock_wrlock failed");
00081       return 1;
00082     }
00083   puts ("2nd rwlock_wrlock succeeded");
00084 
00085   if (pthread_rwlock_unlock (&r) != 0)
00086     {
00087       puts ("4th rwlock_unlock failed");
00088       return 1;
00089     }
00090   puts ("4th rwlock_unlock succeeded");
00091 
00092   if (pthread_rwlock_rdlock (&r) != 0)
00093     {
00094       puts ("3rd rwlock_rdlock failed");
00095       return 1;
00096     }
00097   puts ("3rd rwlock_rdlock succeeded");
00098 
00099   if (pthread_rwlock_unlock (&r) != 0)
00100     {
00101       puts ("5th rwlock_unlock failed");
00102       return 1;
00103     }
00104   puts ("5th rwlock_unlock succeeded");
00105 
00106   if (pthread_rwlock_destroy (&r) != 0)
00107     {
00108       puts ("rwlock_destroy failed");
00109       return 1;
00110     }
00111   puts ("rwlock_destroy succeeded");
00112 
00113   return 0;
00114 }
00115 
00116 #define TEST_FUNCTION do_test ()
00117 #include "../test-skeleton.c"