GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: lib/librthread/rthread_barrier_attr.c Lines: 20 25 80.0 %
Date: 2017-11-07 Branches: 10 18 55.6 %

Line Branch Exec Source
1
/*	$OpenBSD: rthread_barrier_attr.c,v 1.2 2012/04/23 08:30:33 pirofti Exp $	*/
2
/*
3
 * Copyright (c) 2012 Paul Irofti <pirofti@openbsd.org>
4
 *
5
 * Permission to use, copy, modify, and/or distribute this software for any
6
 * purpose with or without fee is hereby granted, provided that the above
7
 * copyright notice and this permission notice appear in all copies.
8
 *
9
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
 */
17
18
#include <errno.h>
19
#include <stdlib.h>
20
21
#include <pthread.h>
22
23
#include "rthread.h"
24
25
int
26
pthread_barrierattr_init(pthread_barrierattr_t *attr)
27
{
28
10
	if (attr == NULL)
29
		return (EINVAL);
30
31
5
	*attr = calloc(1, sizeof **attr);
32
5
	if (*attr == NULL)
33
		return (ENOMEM);
34
35
5
	(*attr)->pshared = PTHREAD_PROCESS_PRIVATE;
36
37
5
	return (0);
38
5
}
39
40
int
41
pthread_barrierattr_destroy(pthread_barrierattr_t *attr)
42
{
43

15
	if (attr == NULL || *attr == NULL)
44
		return (EINVAL);
45
46
5
	free(*attr);
47
5
	return (0);
48
5
}
49
50
int
51
pthread_barrierattr_getpshared(pthread_barrierattr_t *attr, int *pshared)
52
{
53

15
	if (attr == NULL || *attr == NULL)
54
		return (EINVAL);
55
56
5
	*pshared = (*attr)->pshared;
57
58
5
	return (0);
59
5
}
60
61
int
62
pthread_barrierattr_setpshared(pthread_barrierattr_t *attr, int pshared)
63
{
64

30
	if (attr == NULL || *attr == NULL)
65
		return (EINVAL);
66
67
10
	if (pshared != PTHREAD_PROCESS_PRIVATE)
68
5
		return (ENOTSUP);
69
70
5
	(*attr)->pshared = pshared;
71
72
5
	return (0);
73
10
}