1 /* 2 * Copyright (c) 2002, Intel Corporation. All rights reserved. 3 * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com 4 * This file is licensed under the GPL license. For the full content 5 * of this license, see the COPYING file at the top level of this 6 * source tree. 7 8 * Test that pthread_mutex_unlock() 9 * Upon succesful completion, it shall return zero 10 * 11 */ 12 13 #include <pthread.h> 14 #include <stdio.h> 15 #include <errno.h> 16 #include "posixtest.h" 17 18 int main(void) 19 { 20 pthread_mutex_t mutex; 21 int rc; 22 23 /* Initialize a mutex object */ 24 if ((rc = pthread_mutex_init(&mutex, NULL)) != 0) { 25 fprintf(stderr, "Error at pthread_mutex_init(), rc=%d\n", rc); 26 return PTS_UNRESOLVED; 27 } 28 29 if ((rc = pthread_mutex_lock(&mutex)) != 0) { 30 fprintf(stderr, "Error at pthread_mutex_lock(), rc=%d\n", rc); 31 return PTS_UNRESOLVED; 32 } 33 34 /* Release the mutex using pthread_mutex_unlock() */ 35 if ((rc = pthread_mutex_unlock(&mutex)) == 0) { 36 printf("Test PASSED\n"); 37 return PTS_PASS; 38 } 39 40 /* Check if returned values are tolerable */ 41 else if (rc == EPERM) { 42 fprintf(stderr, "Current thread does not own the mutex\n"); 43 return PTS_UNRESOLVED; 44 } else if (rc == EINVAL) { 45 fprintf(stderr, "Invalid mutex object\n"); 46 return PTS_UNRESOLVED; 47 } else if (rc == EAGAIN) { 48 fprintf(stderr, 49 "The maximum number of recursive locks has been exceeded\n"); 50 return PTS_UNRESOLVED; 51 } 52 53 /* Any other returned value means the test failed */ 54 else { 55 printf("Test FAILED\n"); 56 return PTS_FAIL; 57 } 58 } 59