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  * pthread_barrierattr_setpshared()
8  *
9  * The pthread_barrierattr_setpshared( ) function shall
10  * set the process-shared attribute in an initialized attributes object referenced by attr.
11  */
12 
13 
14 #define _XOPEN_SOURCE 600
15 #include <pthread.h>
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <unistd.h>
19 #include <errno.h>
20 #include "posixtest.h"
21 
main()22 int main()
23 {
24 
25 	/* Make sure there is process-shared capability. */
26 	#ifndef PTHREAD_PROCESS_SHARED
27 	  fprintf(stderr,"process-shared attribute is not available for testing\n");
28 	  return PTS_UNSUPPORTED;
29 	#endif
30 
31 	pthread_barrierattr_t ba;
32 	int	pshared = PTHREAD_PROCESS_SHARED;
33 	int 	pshared2 = PTHREAD_PROCESS_PRIVATE;
34 	int	rc;
35 
36 	/* Initialize a barrier attributes object */
37 	if(pthread_barrierattr_init(&ba) != 0)
38 	{
39 		printf("Error at pthread_barrierattr_init()\n");
40 		return PTS_UNRESOLVED;
41 	}
42 
43 	/* Set pshared to PTHREAD_PROCESS_SHARED */
44 	rc = pthread_barrierattr_setpshared(&ba, pshared);
45 	if(rc != 0)
46 	{
47 		printf("Test FAILED: Error at pthread_barrierattr_setpshared()\n");
48 		return PTS_FAIL;
49 	}
50 
51 	if(pthread_barrierattr_getpshared(&ba, &pshared) != 0)
52 	{
53 		printf("Error at pthread_barrierattr_getpshared()\n");
54 		return PTS_FAIL;
55 	}
56 
57 	if(pshared != PTHREAD_PROCESS_SHARED)
58 	{
59 		printf("Test FAILED: Got error shared attribute value %d\n", pshared);
60 		return PTS_FAIL;
61 	}
62 
63 	/* Set pshared to PTHREAD_PROCESS_SHARED */
64 	rc = pthread_barrierattr_setpshared(&ba, pshared2);
65 	if(rc != 0)
66 	{
67 		printf("Test FAILED: Error at pthread_barrierattr_setpshared()\n");
68 		return PTS_FAIL;
69 	}
70 
71 	if(pthread_barrierattr_getpshared(&ba, &pshared2) != 0)
72 	{
73 		printf("Error at pthread_barrierattr_getpshared()\n");
74 		return PTS_FAIL;
75 	}
76 
77 	if(pshared2 != PTHREAD_PROCESS_PRIVATE)
78 	{
79 		printf("Test FAILED: Got error shared attribute value %d\n", pshared);
80 		return PTS_FAIL;
81 	}
82 
83 	printf("Test PASSED\n");
84 	return PTS_PASS;
85 
86 }
87