Home | History | Annotate | Download | only in pthread_mutex_lock
      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_lock()
      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_mutex_t mutex;
     21 	int rc;
     22 
     23 	/* Initialize a mutex object with the default mutex attributes */
     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 	/* Lock the mutex using pthread_mutex_lock() */
     30 	if ((rc = pthread_mutex_lock(&mutex)) == 0) {
     31 		pthread_mutex_unlock(&mutex);
     32 		printf("Test PASSED\n");
     33 		return PTS_PASS;
     34 	}
     35 
     36 	/* Check if returned values are tolerable */
     37 	else if (rc == EINVAL) {
     38 		fprintf(stderr, "Invalid mutex object\n");
     39 		return PTS_UNRESOLVED;
     40 	} else if (rc == EAGAIN) {
     41 		fprintf(stderr,
     42 			"The maximum number of recursive locks has been exceeded\n");
     43 		return PTS_UNRESOLVED;
     44 	} else if (rc == EDEADLK) {
     45 		fprintf(stderr, "The current thread already owns the mutex\n");
     46 		return PTS_UNRESOLVED;
     47 	}
     48 
     49 	/* Any other returned value means the test failed */
     50 	else {
     51 		printf("Test FAILED\n");
     52 		return PTS_FAIL;
     53 	}
     54 }
     55