Home | History | Annotate | Download | only in pthread_mutex_init
      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_init()
      9  *   Upon succesful completion, it shall return a 0
     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_mutexattr_t mta;
     21 	pthread_mutex_t mutex;
     22 	int rc;
     23 
     24 	/* Initialize a mutex attributes object */
     25 	if ((rc = pthread_mutexattr_init(&mta)) != 0) {
     26 		fprintf(stderr, "Error at pthread_mutexattr_init(), rc=%d\n",
     27 			rc);
     28 		return PTS_UNRESOLVED;
     29 	}
     30 
     31 	/* Initialize a mutex object with the default mutex attributes */
     32 	if ((rc = pthread_mutex_init(&mutex, &mta)) == 0) {
     33 		printf("Test PASSED\n");
     34 		return PTS_PASS;
     35 	}
     36 
     37 	/* Check if returned values are tolerable */
     38 	else if (rc == ENOMEM) {
     39 		fprintf(stderr,
     40 			"Insufficient memory to initialize the mutex\n");
     41 		return PTS_UNRESOLVED;
     42 	} else if (rc == EAGAIN) {
     43 		fprintf(stderr,
     44 			"Lack of the necessary resources to initilize the mutex\n");
     45 		return PTS_UNRESOLVED;
     46 	} else if (rc == EPERM) {
     47 		fprintf(stderr, "Permission denied\n");
     48 		return PTS_UNRESOLVED;
     49 	} else if (rc == EBUSY) {
     50 		fprintf(stderr,
     51 			"Detected an attemp to reinitilize a previously initilized mutex\n");
     52 		return PTS_UNRESOLVED;
     53 	}
     54 
     55 	/* Any other returned value means the test failed */
     56 	else {
     57 		printf("Test FAILED\n");
     58 		return PTS_FAIL;
     59 	}
     60 }
     61