xref: /haiku/src/system/libroot/posix/pthread/pthread_condattr.c (revision 922e7ba1f3228e6f28db69b0ded8f86eb32dea17)
1 /*
2  * Copyright 2007, Ryan Leavengood, leavengood@gmail.com.
3  * All rights reserved. Distributed under the terms of the MIT License.
4  */
5 
6 
7 #include <pthread.h>
8 #include "pthread_private.h"
9 
10 #include <stdlib.h>
11 
12 
13 int
14 pthread_condattr_init(pthread_condattr_t *_condAttr)
15 {
16 	pthread_condattr *attr;
17 
18 	if (_condAttr == NULL)
19 		return B_BAD_VALUE;
20 
21 	attr = (pthread_condattr *)malloc(sizeof(pthread_condattr));
22 	if (attr == NULL)
23 		return B_NO_MEMORY;
24 
25 	attr->process_shared = false;
26 
27 	*_condAttr = attr;
28 	return B_OK;
29 }
30 
31 
32 int
33 pthread_condattr_destroy(pthread_condattr_t *_condAttr)
34 {
35 	pthread_condattr *attr;
36 
37 	if (_condAttr == NULL || (attr = *_condAttr) == NULL)
38 		return B_BAD_VALUE;
39 
40 	*_condAttr = NULL;
41 	free(attr);
42 
43 	return B_OK;
44 }
45 
46 
47 int
48 pthread_condattr_getpshared(const pthread_condattr_t *_condAttr, int *_processShared)
49 {
50 	pthread_condattr *attr;
51 
52 	if (_condAttr == NULL || (attr = *_condAttr) == NULL || _processShared == NULL)
53 		return B_BAD_VALUE;
54 
55 	*_processShared = attr->process_shared ? PTHREAD_PROCESS_SHARED : PTHREAD_PROCESS_PRIVATE;
56 	return B_OK;
57 }
58 
59 
60 int
61 pthread_condattr_setpshared(pthread_condattr_t *_condAttr, int processShared)
62 {
63 	pthread_condattr *attr;
64 
65 	if (_condAttr == NULL || (attr = *_condAttr) == NULL
66 		|| processShared < PTHREAD_PROCESS_PRIVATE
67 		|| processShared > PTHREAD_PROCESS_SHARED)
68 		return B_BAD_VALUE;
69 
70 	attr->process_shared = processShared == PTHREAD_PROCESS_SHARED ? true : false;
71 	return B_OK;
72 }
73 
74