headers/bsd: Add sys/queue.h.
[haiku.git] / src / system / libroot / posix / pthread / pthread_mutexattr.c
blobbb109fd3a44dc3664faec49deeaa903a74283530
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 */
7 #include <pthread.h>
8 #include "pthread_private.h"
10 #include <stdlib.h>
13 int
14 pthread_mutexattr_init(pthread_mutexattr_t *_mutexAttr)
16 pthread_mutexattr *attr;
18 if (_mutexAttr == NULL)
19 return B_BAD_VALUE;
21 attr = (pthread_mutexattr *)malloc(sizeof(pthread_mutexattr));
22 if (attr == NULL)
23 return B_NO_MEMORY;
25 attr->type = PTHREAD_MUTEX_DEFAULT;
26 attr->process_shared = false;
28 *_mutexAttr = attr;
29 return B_OK;
33 int
34 pthread_mutexattr_destroy(pthread_mutexattr_t *_mutexAttr)
36 pthread_mutexattr *attr;
38 if (_mutexAttr == NULL || (attr = *_mutexAttr) == NULL)
39 return B_BAD_VALUE;
41 *_mutexAttr = NULL;
42 free(attr);
44 return B_OK;
48 int
49 pthread_mutexattr_gettype(const pthread_mutexattr_t *_mutexAttr, int *_type)
51 pthread_mutexattr *attr;
53 if (_mutexAttr == NULL || (attr = *_mutexAttr) == NULL || _type == NULL)
54 return B_BAD_VALUE;
56 *_type = attr->type;
57 return B_OK;
61 int
62 pthread_mutexattr_settype(pthread_mutexattr_t *_mutexAttr, int type)
64 pthread_mutexattr *attr;
66 if (_mutexAttr == NULL || (attr = *_mutexAttr) == NULL
67 || type < PTHREAD_MUTEX_DEFAULT
68 || type > PTHREAD_MUTEX_RECURSIVE)
69 return B_BAD_VALUE;
71 attr->type = type;
72 return B_OK;
76 int
77 pthread_mutexattr_getpshared(const pthread_mutexattr_t *_mutexAttr,
78 int *_processShared)
80 pthread_mutexattr *attr;
82 if (_mutexAttr == NULL || (attr = *_mutexAttr) == NULL
83 || _processShared == NULL) {
84 return B_BAD_VALUE;
87 *_processShared = attr->process_shared ? PTHREAD_PROCESS_SHARED
88 : PTHREAD_PROCESS_PRIVATE;
89 return B_OK;
93 int
94 pthread_mutexattr_setpshared(pthread_mutexattr_t *_mutexAttr,
95 int processShared)
97 pthread_mutexattr *attr;
99 if (_mutexAttr == NULL || (attr = *_mutexAttr) == NULL
100 || processShared < PTHREAD_PROCESS_PRIVATE
101 || processShared > PTHREAD_PROCESS_SHARED) {
102 return B_BAD_VALUE;
105 attr->process_shared = processShared == PTHREAD_PROCESS_SHARED;
106 return B_OK;
110 int
111 pthread_mutexattr_getprioceiling(const pthread_mutexattr_t *_mutexAttr,
112 int *_priorityCeiling)
114 pthread_mutexattr *attr;
116 if (_mutexAttr == NULL || (attr = *_mutexAttr) == NULL
117 || _priorityCeiling == NULL) {
118 return B_BAD_VALUE;
121 *_priorityCeiling = 0;
122 // not implemented
124 return B_OK;
128 int
129 pthread_mutexattr_setprioceiling(pthread_mutexattr_t *_mutexAttr,
130 int priorityCeiling)
132 pthread_mutexattr *attr;
134 if (_mutexAttr == NULL || (attr = *_mutexAttr) == NULL)
135 return B_BAD_VALUE;
137 // not implemented
138 return B_NOT_ALLOWED;
142 int
143 pthread_mutexattr_getprotocol(const pthread_mutexattr_t *_mutexAttr,
144 int *_protocol)
146 pthread_mutexattr *attr;
148 if (_mutexAttr == NULL || (attr = *_mutexAttr) == NULL
149 || _protocol == NULL) {
150 return B_BAD_VALUE;
153 *_protocol = 0;
154 // not implemented
156 return B_OK;
160 int
161 pthread_mutexattr_setprotocol(pthread_mutexattr_t *_mutexAttr, int protocol)
163 pthread_mutexattr *attr;
165 if (_mutexAttr == NULL || (attr = *_mutexAttr) == NULL)
166 return B_BAD_VALUE;
168 // not implemented
169 return B_NOT_ALLOWED;