(root)/
glibc-2.38/
sysdeps/
pthread/
tst-rwlock1.c
       1  /* Copyright (C) 2002-2023 Free Software Foundation, Inc.
       2     This file is part of the GNU C Library.
       3  
       4     The GNU C Library is free software; you can redistribute it and/or
       5     modify it under the terms of the GNU Lesser General Public
       6     License as published by the Free Software Foundation; either
       7     version 2.1 of the License, or (at your option) any later version.
       8  
       9     The GNU C Library is distributed in the hope that it will be useful,
      10     but WITHOUT ANY WARRANTY; without even the implied warranty of
      11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      12     Lesser General Public License for more details.
      13  
      14     You should have received a copy of the GNU Lesser General Public
      15     License along with the GNU C Library; if not, see
      16     <https://www.gnu.org/licenses/>.  */
      17  
      18  #include <pthread.h>
      19  #include <stdio.h>
      20  
      21  
      22  static int
      23  do_test (void)
      24  {
      25    pthread_rwlock_t r;
      26  
      27    if (pthread_rwlock_init (&r, NULL) != 0)
      28      {
      29        puts ("rwlock_init failed");
      30        return 1;
      31      }
      32    puts ("rwlock_init succeeded");
      33  
      34    if (pthread_rwlock_rdlock (&r) != 0)
      35      {
      36        puts ("1st rwlock_rdlock failed");
      37        return 1;
      38      }
      39    puts ("1st rwlock_rdlock succeeded");
      40  
      41    if (pthread_rwlock_rdlock (&r) != 0)
      42      {
      43        puts ("2nd rwlock_rdlock failed");
      44        return 1;
      45      }
      46    puts ("2nd rwlock_rdlock succeeded");
      47  
      48    if (pthread_rwlock_unlock (&r) != 0)
      49      {
      50        puts ("1st rwlock_unlock failed");
      51        return 1;
      52      }
      53    puts ("1st rwlock_unlock succeeded");
      54  
      55    if (pthread_rwlock_unlock (&r) != 0)
      56      {
      57        puts ("2nd rwlock_unlock failed");
      58        return 1;
      59      }
      60    puts ("2nd rwlock_unlock succeeded");
      61  
      62    if (pthread_rwlock_wrlock (&r) != 0)
      63      {
      64        puts ("1st rwlock_wrlock failed");
      65        return 1;
      66      }
      67    puts ("1st rwlock_wrlock succeeded");
      68  
      69    if (pthread_rwlock_unlock (&r) != 0)
      70      {
      71        puts ("3rd rwlock_unlock failed");
      72        return 1;
      73      }
      74    puts ("3rd rwlock_unlock succeeded");
      75  
      76    if (pthread_rwlock_wrlock (&r) != 0)
      77      {
      78        puts ("2nd rwlock_wrlock failed");
      79        return 1;
      80      }
      81    puts ("2nd rwlock_wrlock succeeded");
      82  
      83    if (pthread_rwlock_unlock (&r) != 0)
      84      {
      85        puts ("4th rwlock_unlock failed");
      86        return 1;
      87      }
      88    puts ("4th rwlock_unlock succeeded");
      89  
      90    if (pthread_rwlock_rdlock (&r) != 0)
      91      {
      92        puts ("3rd rwlock_rdlock failed");
      93        return 1;
      94      }
      95    puts ("3rd rwlock_rdlock succeeded");
      96  
      97    if (pthread_rwlock_unlock (&r) != 0)
      98      {
      99        puts ("5th rwlock_unlock failed");
     100        return 1;
     101      }
     102    puts ("5th rwlock_unlock succeeded");
     103  
     104    if (pthread_rwlock_destroy (&r) != 0)
     105      {
     106        puts ("rwlock_destroy failed");
     107        return 1;
     108      }
     109    puts ("rwlock_destroy succeeded");
     110  
     111    return 0;
     112  }
     113  
     114  #define TEST_FUNCTION do_test ()
     115  #include "../test-skeleton.c"