headers/bsd: Add sys/queue.h.
[haiku.git] / src / system / libroot / posix / pthread / pthread_condattr.c
blob34addb92b055bfc537034a68b998b9fcc42ec264
1 /*
2 * Copyright 2007, Ryan Leavengood, leavengood@gmail.com.
3 * All rights reserved. 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_condattr_init(pthread_condattr_t *_condAttr)
16 pthread_condattr *attr;
18 if (_condAttr == NULL)
19 return B_BAD_VALUE;
21 attr = (pthread_condattr *)malloc(sizeof(pthread_condattr));
22 if (attr == NULL)
23 return B_NO_MEMORY;
25 attr->process_shared = false;
26 attr->clock_id = CLOCK_REALTIME;
28 *_condAttr = attr;
29 return B_OK;
33 int
34 pthread_condattr_destroy(pthread_condattr_t *_condAttr)
36 pthread_condattr *attr;
38 if (_condAttr == NULL || (attr = *_condAttr) == NULL)
39 return B_BAD_VALUE;
41 *_condAttr = NULL;
42 free(attr);
44 return B_OK;
48 int
49 pthread_condattr_getpshared(const pthread_condattr_t *_condAttr, int *_processShared)
51 pthread_condattr *attr;
53 if (_condAttr == NULL || (attr = *_condAttr) == NULL || _processShared == NULL)
54 return B_BAD_VALUE;
56 *_processShared = attr->process_shared ? PTHREAD_PROCESS_SHARED : PTHREAD_PROCESS_PRIVATE;
57 return B_OK;
61 int
62 pthread_condattr_setpshared(pthread_condattr_t *_condAttr, int processShared)
64 pthread_condattr *attr;
66 if (_condAttr == NULL || (attr = *_condAttr) == NULL
67 || processShared < PTHREAD_PROCESS_PRIVATE
68 || processShared > PTHREAD_PROCESS_SHARED)
69 return B_BAD_VALUE;
71 attr->process_shared = processShared == PTHREAD_PROCESS_SHARED ? true : false;
72 return B_OK;
76 int
77 pthread_condattr_getclock(const pthread_condattr_t *_condAttr, clockid_t *_clockID)
79 pthread_condattr *attr;
81 if (_condAttr == NULL || (attr = *_condAttr) == NULL || _clockID == NULL)
82 return B_BAD_VALUE;
84 *_clockID = attr->clock_id;
85 return B_OK;
89 int
90 pthread_condattr_setclock(pthread_condattr_t *_condAttr, clockid_t clockID)
92 pthread_condattr *attr;
94 if (_condAttr == NULL || (attr = *_condAttr) == NULL
95 || (clockID != CLOCK_REALTIME && clockID != CLOCK_MONOTONIC))
96 return B_BAD_VALUE;
98 attr->clock_id = clockID;
99 return B_OK;