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_barrier_init()
8 *
9 *
10 * The pthread_barrier_init() function shall allocate any resources
11 * required to use the barrier referenced by barrier and shall initialize
12 * the barrier with attributes referenced by attr. If attr is NULL,
13 * the default barrier attributes shall be used;
14 * the effect is the same as passing the address of a default barrier attributes object.
15 *
16 */
17
18#define _XOPEN_SOURCE 600
19#include <pthread.h>
20#include <stdio.h>
21#include <stdlib.h>
22#include <unistd.h>
23#include <signal.h>
24#include <errno.h>
25#include <string.h>
26#include "posixtest.h"
27
28#define COUNT 1
29
30static pthread_barrier_t barrier;
31
32int main(void)
33{
34	int rc;
35	pthread_barrierattr_t ba;
36
37	/* Intilized barrier with NULL attribute, check that this can be done. */
38	rc = pthread_barrier_init(&barrier, NULL, COUNT);
39
40	if (rc != 0) {
41		printf("Test FAILED: Error at pthread_barrier_init() "
42		       "return code %d, %s\n", rc, strerror(rc));
43		return PTS_FAIL;
44	}
45
46	/* Cleanup */
47	if (pthread_barrier_destroy(&barrier) != 0) {
48		printf("Error at pthread_barrier_destroy() "
49		       " return code: %d, %s\n", rc, strerror(rc));
50		return PTS_UNRESOLVED;
51	}
52
53	/* Initialize a barrier attribute object */
54	if (pthread_barrierattr_init(&ba) != 0) {
55		printf("Error at pthread_barrierattr_init()\n");
56		return PTS_UNRESOLVED;
57	}
58
59	/* Initialize barrier with this barrier attribute object */
60	rc = pthread_barrier_init(&barrier, &ba, COUNT);
61	if (rc != 0) {
62		printf("Test FAILED: Error at 2nd pthread_barrier_init() "
63		       "return code %d, %s\n", rc, strerror(rc));
64		return PTS_FAIL;
65	}
66
67	/* Cleanup */
68	if (pthread_barrierattr_destroy(&ba) != 0) {
69		printf("Error at pthread_barrierattr_destroy()\n");
70		return PTS_UNRESOLVED;
71	}
72
73	if (pthread_barrier_destroy(&barrier) != 0) {
74		printf("Error at pthread_barrier_destroy() "
75		       " return code: %d, %s\n", rc, strerror(rc));
76		return PTS_UNRESOLVED;
77	}
78
79	printf("Test PASSED\n");
80	return PTS_PASS;
81}
82