Assorted whitespace cleanup and typo fixes.
[haiku.git] / src / system / libroot / posix / pthread / pthread_mutexattr.c
blob605d1331be6272d125488305813ceb5cebc35863
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(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(pthread_mutexattr_t *_mutexAttr, int *_processShared)
79 pthread_mutexattr *attr;
81 if (_mutexAttr == NULL || (attr = *_mutexAttr) == NULL || _processShared == NULL)
82 return B_BAD_VALUE;
84 *_processShared = attr->process_shared ? PTHREAD_PROCESS_SHARED : PTHREAD_PROCESS_PRIVATE;
85 return B_OK;
89 int
90 pthread_mutexattr_setpshared(pthread_mutexattr_t *_mutexAttr, int processShared)
92 pthread_mutexattr *attr;
94 if (_mutexAttr == NULL || (attr = *_mutexAttr) == NULL
95 || processShared < PTHREAD_PROCESS_PRIVATE
96 || processShared > PTHREAD_PROCESS_SHARED)
97 return B_BAD_VALUE;
99 attr->process_shared = processShared == PTHREAD_PROCESS_SHARED ? true : false;
100 return B_OK;
104 int
105 pthread_mutexattr_getprioceiling(pthread_mutexattr_t *_mutexAttr, int *_priorityCeiling)
107 pthread_mutexattr *attr;
109 if (_mutexAttr == NULL || (attr = *_mutexAttr) == NULL || _priorityCeiling == NULL)
110 return B_BAD_VALUE;
112 *_priorityCeiling = 0;
113 // not implemented
115 return B_OK;
119 int
120 pthread_mutexattr_setprioceiling(pthread_mutexattr_t *_mutexAttr, int priorityCeiling)
122 pthread_mutexattr *attr;
124 if (_mutexAttr == NULL || (attr = *_mutexAttr) == NULL)
125 return B_BAD_VALUE;
127 // not implemented
128 return B_NOT_ALLOWED;
132 int
133 pthread_mutexattr_getprotocol(pthread_mutexattr_t *_mutexAttr, int *_protocol)
135 pthread_mutexattr *attr;
137 if (_mutexAttr == NULL || (attr = *_mutexAttr) == NULL || _protocol == NULL)
138 return B_BAD_VALUE;
140 *_protocol = 0;
141 // not implemented
143 return B_OK;
147 int
148 pthread_mutexattr_setprotocol(pthread_mutexattr_t *_mutexAttr, int protocol)
150 pthread_mutexattr *attr;
152 if (_mutexAttr == NULL || (attr = *_mutexAttr) == NULL)
153 return B_BAD_VALUE;
155 // not implemented
156 return B_NOT_ALLOWED;