1 /* 2 * Copyright (c) 2002, Intel Corporation. All rights reserved. 3 * This file is licensed under the GPL license. For the full content 4 * of this license, see the COPYING file at the top level of this 5 * source tree. 6 * 7 * Test pthread_rwlock_init(). 8 * 9 * May fail if: 10 * [EBUSY] The implementation has detected an attempt to reinitialize the object 11 * referenced by rwlock, a previously initialized but not yet destroyed read-write 12 * lock. 13 * 14 * Steps: 15 * 1. Initialize a pthread_rwlock_t object 'rwlock' with pthread_rwlock_init(). 16 * 2. Re-initialize it again without destroying it first. 17 * 18 */ 19 #define _XOPEN_SOURCE 600 20 #include <pthread.h> 21 #include <stdio.h> 22 #include <stdlib.h> 23 #include <unistd.h> 24 #include <errno.h> 25 #include "posixtest.h" 26 27 int main(void) 28 { 29 30 static pthread_rwlock_t rwlock; 31 int rc; 32 33 /* Initialize the rwlock */ 34 rc = pthread_rwlock_init(&rwlock, NULL); 35 if (rc != 0) { 36 printf 37 ("Test FAILED: Error at pthread_rwlock_init(), returns %d\n", 38 rc); 39 return PTS_FAIL; 40 } 41 42 /* Re-intialize without destroying it first */ 43 rc = pthread_rwlock_init(&rwlock, NULL); 44 45 /* Cleanup */ 46 if (pthread_rwlock_destroy(&rwlock) != 0) { 47 printf("Error at pthread_rwlock_destroy()\n"); 48 return PTS_UNRESOLVED; 49 } 50 51 if (rc == EBUSY) { 52 printf("Test PASSED\n"); 53 return PTS_PASS; 54 } else if (rc == 0) { 55 printf 56 ("Test PASSED: Note*: pthread_rwlock_init() returned 0 instead of EBUSY, but standard specifies _may_ fail\n"); 57 return PTS_PASS; 58 } else { 59 printf 60 ("Test FAILED: Error at pthread_rwlock_init(), should return 0 or EBUSY, but returns %d\n", 61 rc); 62 return PTS_FAIL; 63 } 64 65 } 66