1 /*
2 * Copyright 2003-2007, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3 * 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
pthread_mutexattr_init(pthread_mutexattr_t * _mutexAttr)14 pthread_mutexattr_init(pthread_mutexattr_t *_mutexAttr)
15 {
16 pthread_mutexattr *attr;
17
18 if (_mutexAttr == NULL)
19 return B_BAD_VALUE;
20
21 attr = (pthread_mutexattr *)malloc(sizeof(pthread_mutexattr));
22 if (attr == NULL)
23 return B_NO_MEMORY;
24
25 attr->type = PTHREAD_MUTEX_DEFAULT;
26 attr->process_shared = false;
27
28 *_mutexAttr = attr;
29 return B_OK;
30 }
31
32
33 int
pthread_mutexattr_destroy(pthread_mutexattr_t * _mutexAttr)34 pthread_mutexattr_destroy(pthread_mutexattr_t *_mutexAttr)
35 {
36 pthread_mutexattr *attr;
37
38 if (_mutexAttr == NULL || (attr = *_mutexAttr) == NULL)
39 return B_BAD_VALUE;
40
41 *_mutexAttr = NULL;
42 free(attr);
43
44 return B_OK;
45 }
46
47
48 int
pthread_mutexattr_gettype(const pthread_mutexattr_t * _mutexAttr,int * _type)49 pthread_mutexattr_gettype(const pthread_mutexattr_t *_mutexAttr, int *_type)
50 {
51 pthread_mutexattr *attr;
52
53 if (_mutexAttr == NULL || (attr = *_mutexAttr) == NULL || _type == NULL)
54 return B_BAD_VALUE;
55
56 *_type = attr->type;
57 return B_OK;
58 }
59
60
61 int
pthread_mutexattr_settype(pthread_mutexattr_t * _mutexAttr,int type)62 pthread_mutexattr_settype(pthread_mutexattr_t *_mutexAttr, int type)
63 {
64 pthread_mutexattr *attr;
65
66 if (_mutexAttr == NULL || (attr = *_mutexAttr) == NULL
67 || type < PTHREAD_MUTEX_DEFAULT
68 || type > PTHREAD_MUTEX_RECURSIVE)
69 return B_BAD_VALUE;
70
71 attr->type = type;
72 return B_OK;
73 }
74
75
76 int
pthread_mutexattr_getpshared(const pthread_mutexattr_t * _mutexAttr,int * _processShared)77 pthread_mutexattr_getpshared(const pthread_mutexattr_t *_mutexAttr,
78 int *_processShared)
79 {
80 pthread_mutexattr *attr;
81
82 if (_mutexAttr == NULL || (attr = *_mutexAttr) == NULL
83 || _processShared == NULL) {
84 return B_BAD_VALUE;
85 }
86
87 *_processShared = attr->process_shared ? PTHREAD_PROCESS_SHARED
88 : PTHREAD_PROCESS_PRIVATE;
89 return B_OK;
90 }
91
92
93 int
pthread_mutexattr_setpshared(pthread_mutexattr_t * _mutexAttr,int processShared)94 pthread_mutexattr_setpshared(pthread_mutexattr_t *_mutexAttr,
95 int processShared)
96 {
97 pthread_mutexattr *attr;
98
99 if (_mutexAttr == NULL || (attr = *_mutexAttr) == NULL
100 || processShared < PTHREAD_PROCESS_PRIVATE
101 || processShared > PTHREAD_PROCESS_SHARED) {
102 return B_BAD_VALUE;
103 }
104
105 attr->process_shared = processShared == PTHREAD_PROCESS_SHARED;
106 return B_OK;
107 }
108
109
110 int
pthread_mutexattr_getprioceiling(const pthread_mutexattr_t * _mutexAttr,int * _priorityCeiling)111 pthread_mutexattr_getprioceiling(const pthread_mutexattr_t *_mutexAttr,
112 int *_priorityCeiling)
113 {
114 pthread_mutexattr *attr;
115
116 if (_mutexAttr == NULL || (attr = *_mutexAttr) == NULL
117 || _priorityCeiling == NULL) {
118 return B_BAD_VALUE;
119 }
120
121 *_priorityCeiling = 0;
122 // not implemented
123
124 return B_OK;
125 }
126
127
128 int
pthread_mutexattr_setprioceiling(pthread_mutexattr_t * _mutexAttr,int priorityCeiling)129 pthread_mutexattr_setprioceiling(pthread_mutexattr_t *_mutexAttr,
130 int priorityCeiling)
131 {
132 pthread_mutexattr *attr;
133
134 if (_mutexAttr == NULL || (attr = *_mutexAttr) == NULL)
135 return B_BAD_VALUE;
136
137 // not implemented
138 return B_NOT_ALLOWED;
139 }
140
141
142 int
pthread_mutexattr_getprotocol(const pthread_mutexattr_t * _mutexAttr,int * _protocol)143 pthread_mutexattr_getprotocol(const pthread_mutexattr_t *_mutexAttr,
144 int *_protocol)
145 {
146 pthread_mutexattr *attr;
147
148 if (_mutexAttr == NULL || (attr = *_mutexAttr) == NULL
149 || _protocol == NULL) {
150 return B_BAD_VALUE;
151 }
152
153 *_protocol = 0;
154 // not implemented
155
156 return B_OK;
157 }
158
159
160 int
pthread_mutexattr_setprotocol(pthread_mutexattr_t * _mutexAttr,int protocol)161 pthread_mutexattr_setprotocol(pthread_mutexattr_t *_mutexAttr, int protocol)
162 {
163 pthread_mutexattr *attr;
164
165 if (_mutexAttr == NULL || (attr = *_mutexAttr) == NULL)
166 return B_BAD_VALUE;
167
168 // not implemented
169 return B_NOT_ALLOWED;
170 }
171