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 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 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 49 pthread_mutexattr_gettype(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 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 77 pthread_mutexattr_getpshared(pthread_mutexattr_t *_mutexAttr, int *_processShared) 78 { 79 pthread_mutexattr *attr; 80 81 if (_mutexAttr == NULL || (attr = *_mutexAttr) == NULL || _processShared == NULL) 82 return B_BAD_VALUE; 83 84 *_processShared = attr->process_shared ? PTHREAD_PROCESS_SHARED : PTHREAD_PROCESS_PRIVATE; 85 return B_OK; 86 } 87 88 89 int 90 pthread_mutexattr_setpshared(pthread_mutexattr_t *_mutexAttr, int processShared) 91 { 92 pthread_mutexattr *attr; 93 94 if (_mutexAttr == NULL || (attr = *_mutexAttr) == NULL 95 || processShared < PTHREAD_PROCESS_PRIVATE 96 || processShared > PTHREAD_PROCESS_SHARED) 97 return B_BAD_VALUE; 98 99 attr->process_shared = processShared == PTHREAD_PROCESS_SHARED ? true : false; 100 return B_OK; 101 } 102 103 104 int 105 pthread_mutexattr_getprioceiling(pthread_mutexattr_t *_mutexAttr, int *_priorityCeiling) 106 { 107 pthread_mutexattr *attr; 108 109 if (_mutexAttr == NULL || (attr = *_mutexAttr) == NULL || _priorityCeiling == NULL) 110 return B_BAD_VALUE; 111 112 *_priorityCeiling = 0; 113 // not implemented 114 115 return B_OK; 116 } 117 118 119 int 120 pthread_mutexattr_setprioceiling(pthread_mutexattr_t *_mutexAttr, int priorityCeiling) 121 { 122 pthread_mutexattr *attr; 123 124 if (_mutexAttr == NULL || (attr = *_mutexAttr) == NULL) 125 return B_BAD_VALUE; 126 127 // not implemented 128 return B_NOT_ALLOWED; 129 } 130 131 132 int 133 pthread_mutexattr_getprotocol(pthread_mutexattr_t *_mutexAttr, int *_protocol) 134 { 135 pthread_mutexattr *attr; 136 137 if (_mutexAttr == NULL || (attr = *_mutexAttr) == NULL || _protocol == NULL) 138 return B_BAD_VALUE; 139 140 *_protocol = 0; 141 // not implemented 142 143 return B_OK; 144 } 145 146 147 int 148 pthread_mutexattr_setprotocol(pthread_mutexattr_t *_mutexAttr, int protocol) 149 { 150 pthread_mutexattr *attr; 151 152 if (_mutexAttr == NULL || (attr = *_mutexAttr) == NULL) 153 return B_BAD_VALUE; 154 155 // not implemented 156 return B_NOT_ALLOWED; 157 } 158