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 attr->clock_id = CLOCK_REALTIME; 27 28 *_condAttr = attr; 29 return B_OK; 30 } 31 32 33 int 34 pthread_condattr_destroy(pthread_condattr_t *_condAttr) 35 { 36 pthread_condattr *attr; 37 38 if (_condAttr == NULL || (attr = *_condAttr) == NULL) 39 return B_BAD_VALUE; 40 41 *_condAttr = NULL; 42 free(attr); 43 44 return B_OK; 45 } 46 47 48 int 49 pthread_condattr_getpshared(const pthread_condattr_t *_condAttr, int *_processShared) 50 { 51 pthread_condattr *attr; 52 53 if (_condAttr == NULL || (attr = *_condAttr) == NULL || _processShared == NULL) 54 return B_BAD_VALUE; 55 56 *_processShared = attr->process_shared ? PTHREAD_PROCESS_SHARED : PTHREAD_PROCESS_PRIVATE; 57 return B_OK; 58 } 59 60 61 int 62 pthread_condattr_setpshared(pthread_condattr_t *_condAttr, int processShared) 63 { 64 pthread_condattr *attr; 65 66 if (_condAttr == NULL || (attr = *_condAttr) == NULL 67 || processShared < PTHREAD_PROCESS_PRIVATE 68 || processShared > PTHREAD_PROCESS_SHARED) 69 return B_BAD_VALUE; 70 71 attr->process_shared = processShared == PTHREAD_PROCESS_SHARED ? true : false; 72 return B_OK; 73 } 74 75 76 int 77 pthread_condattr_getclock(const pthread_condattr_t *_condAttr, clockid_t *_clockID) 78 { 79 pthread_condattr *attr; 80 81 if (_condAttr == NULL || (attr = *_condAttr) == NULL || _clockID == NULL) 82 return B_BAD_VALUE; 83 84 *_clockID = attr->clock_id; 85 return B_OK; 86 } 87 88 89 int 90 pthread_condattr_setclock(pthread_condattr_t *_condAttr, clockid_t clockID) 91 { 92 pthread_condattr *attr; 93 94 if (_condAttr == NULL || (attr = *_condAttr) == NULL 95 || (clockID != CLOCK_REALTIME && clockID != CLOCK_MONOTONIC)) 96 return B_BAD_VALUE; 97 98 attr->clock_id = clockID; 99 return B_OK; 100 } 101