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 |
✗✓ |
6 |
if (attr == NULL) |
29 |
|
|
return (EINVAL); |
30 |
|
|
|
31 |
|
3 |
*attr = calloc(1, sizeof **attr); |
32 |
✗✓ |
3 |
if (*attr == NULL) |
33 |
|
|
return (ENOMEM); |
34 |
|
|
|
35 |
|
3 |
(*attr)->pshared = PTHREAD_PROCESS_PRIVATE; |
36 |
|
|
|
37 |
|
3 |
return (0); |
38 |
|
3 |
} |
39 |
|
|
|
40 |
|
|
int |
41 |
|
|
pthread_barrierattr_destroy(pthread_barrierattr_t *attr) |
42 |
|
|
{ |
43 |
✓✗✗✓
|
9 |
if (attr == NULL || *attr == NULL) |
44 |
|
|
return (EINVAL); |
45 |
|
|
|
46 |
|
3 |
free(*attr); |
47 |
|
3 |
return (0); |
48 |
|
3 |
} |
49 |
|
|
|
50 |
|
|
int |
51 |
|
|
pthread_barrierattr_getpshared(pthread_barrierattr_t *attr, int *pshared) |
52 |
|
|
{ |
53 |
✓✗✗✓
|
9 |
if (attr == NULL || *attr == NULL) |
54 |
|
|
return (EINVAL); |
55 |
|
|
|
56 |
|
3 |
*pshared = (*attr)->pshared; |
57 |
|
|
|
58 |
|
3 |
return (0); |
59 |
|
3 |
} |
60 |
|
|
|
61 |
|
|
int |
62 |
|
|
pthread_barrierattr_setpshared(pthread_barrierattr_t *attr, int pshared) |
63 |
|
|
{ |
64 |
✓✗✗✓
|
18 |
if (attr == NULL || *attr == NULL) |
65 |
|
|
return (EINVAL); |
66 |
|
|
|
67 |
✓✓ |
6 |
if (pshared != PTHREAD_PROCESS_PRIVATE) |
68 |
|
3 |
return (ENOTSUP); |
69 |
|
|
|
70 |
|
3 |
(*attr)->pshared = pshared; |
71 |
|
|
|
72 |
|
3 |
return (0); |
73 |
|
6 |
} |