Home | History | Annotate | Download | only in pthread_mutexattr_gettype
      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_mutexattr_gettype()
      9  *
     10  * Gets the mutex 'type' attribute.  This attribute is set in the 'type' parameter to
     11  * these functions.  The default value is PTHREAD_MUTEX_DEFAULT.
     12  *
     13  * Testing the PTHREAD_MUTEX_RECURSIVE type.
     14  *
     15  * Steps:
     16  * 1.  Initialize a pthread_mutexattr_t object with pthread_mutexattr_init()
     17  * 2.  Set tye mutexattr type to PTHREAD_MUTEX_RECURSIVE
     18  * 3.  Call pthread_mutexattr_gettype() to check if type
     19  *     attribute is set as the value PTHREAD_MUTEX_RECURSIVE.
     20  *
     21  */
     22 
     23 
     24 #include <pthread.h>
     25 #include <stdio.h>
     26 #include "posixtest.h"
     27 
     28 int main(void)
     29 {
     30 	pthread_mutexattr_t mta;
     31 	int type;
     32 
     33 	/* Initialize a mutex attributes object */
     34 	if (pthread_mutexattr_init(&mta) != 0) {
     35 		perror("Error at pthread_mutexattr_init()\n");
     36 		return PTS_UNRESOLVED;
     37 	}
     38 
     39 	/* Set the mutex attribute 'type' to PTHREAD_MUTEX_RECURSIVE. */
     40 	if (pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_RECURSIVE) != 0) {
     41 		fprintf(stderr,
     42 			"pthread_mutexattr_settype(): Error setting the attribute 'type'\n");
     43 		return PTS_UNRESOLVED;
     44 	}
     45 
     46 	/* The 'type' attribute should be PTHREAD_MUTEX_RECURSIVE  */
     47 	if (pthread_mutexattr_gettype(&mta, &type) != 0) {
     48 		fprintf(stderr,
     49 			"pthread_mutexattr_gettype(): Error obtaining the attribute 'type'\n");
     50 		return PTS_UNRESOLVED;
     51 	}
     52 
     53 	if (type != PTHREAD_MUTEX_RECURSIVE) {
     54 		printf
     55 		    ("Test FAILED: Incorrect mutexattr 'type' value: %d. Should be PTHREAD_MUTEX_RECURSIVE\n",
     56 		     type);
     57 		return PTS_FAIL;
     58 	}
     59 
     60 	printf("Test PASSED\n");
     61 	return PTS_PASS;
     62 }
     63