thr_cond.c (31375) | thr_cond.c (31402) |
---|---|
1/* 2 * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 30 unchanged lines hidden (view full) --- 39int 40pthread_cond_init(pthread_cond_t * cond, const pthread_condattr_t * cond_attr) 41{ 42 enum pthread_cond_type type; 43 pthread_cond_t pcond; 44 int rval = 0; 45 46 if (cond == NULL) { | 1/* 2 * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 30 unchanged lines hidden (view full) --- 39int 40pthread_cond_init(pthread_cond_t * cond, const pthread_condattr_t * cond_attr) 41{ 42 enum pthread_cond_type type; 43 pthread_cond_t pcond; 44 int rval = 0; 45 46 if (cond == NULL) { |
47 errno = EINVAL; 48 rval = -1; | 47 rval = EINVAL; |
49 } else { 50 /* 51 * Check if a pointer to a condition variable attribute 52 * structure was passed by the caller: 53 */ 54 if (cond_attr != NULL && *cond_attr != NULL) { 55 /* Default to a fast condition variable: */ 56 type = (*cond_attr)->c_type; --- 7 unchanged lines hidden (view full) --- 64 /* Fast condition variable: */ 65 case COND_TYPE_FAST: 66 /* Nothing to do here. */ 67 break; 68 69 /* Trap invalid condition variable types: */ 70 default: 71 /* Return an invalid argument error: */ | 48 } else { 49 /* 50 * Check if a pointer to a condition variable attribute 51 * structure was passed by the caller: 52 */ 53 if (cond_attr != NULL && *cond_attr != NULL) { 54 /* Default to a fast condition variable: */ 55 type = (*cond_attr)->c_type; --- 7 unchanged lines hidden (view full) --- 63 /* Fast condition variable: */ 64 case COND_TYPE_FAST: 65 /* Nothing to do here. */ 66 break; 67 68 /* Trap invalid condition variable types: */ 69 default: 70 /* Return an invalid argument error: */ |
72 errno = EINVAL; 73 rval = -1; | 71 rval = EINVAL; |
74 break; 75 } 76 77 /* Check for no errors: */ 78 if (rval == 0) { 79 if ((pcond = (pthread_cond_t) 80 malloc(sizeof(struct pthread_cond))) == NULL) { | 72 break; 73 } 74 75 /* Check for no errors: */ 76 if (rval == 0) { 77 if ((pcond = (pthread_cond_t) 78 malloc(sizeof(struct pthread_cond))) == NULL) { |
81 errno = ENOMEM; 82 rval = -1; | 79 rval = ENOMEM; |
83 } else { 84 /* 85 * Initialise the condition variable 86 * structure: 87 */ 88 _thread_queue_init(&pcond->c_queue); 89 pcond->c_flags |= COND_FLAGS_INITED; 90 pcond->c_type = type; --- 6 unchanged lines hidden (view full) --- 97} 98 99int 100pthread_cond_destroy(pthread_cond_t * cond) 101{ 102 int rval = 0; 103 104 if (cond == NULL || *cond == NULL) { | 80 } else { 81 /* 82 * Initialise the condition variable 83 * structure: 84 */ 85 _thread_queue_init(&pcond->c_queue); 86 pcond->c_flags |= COND_FLAGS_INITED; 87 pcond->c_type = type; --- 6 unchanged lines hidden (view full) --- 94} 95 96int 97pthread_cond_destroy(pthread_cond_t * cond) 98{ 99 int rval = 0; 100 101 if (cond == NULL || *cond == NULL) { |
105 errno = EINVAL; 106 rval = -1; | 102 rval = EINVAL; |
107 } else { 108 /* Process according to condition variable type: */ 109 switch ((*cond)->c_type) { 110 /* Fast condition variable: */ 111 case COND_TYPE_FAST: 112 /* Nothing to do here. */ 113 break; 114 115 /* Trap invalid condition variable types: */ 116 default: 117 /* Return an invalid argument error: */ | 103 } else { 104 /* Process according to condition variable type: */ 105 switch ((*cond)->c_type) { 106 /* Fast condition variable: */ 107 case COND_TYPE_FAST: 108 /* Nothing to do here. */ 109 break; 110 111 /* Trap invalid condition variable types: */ 112 default: 113 /* Return an invalid argument error: */ |
118 errno = EINVAL; 119 rval = -1; | 114 rval = EINVAL; |
120 break; 121 } 122 123 /* Check for errors: */ 124 if (rval == 0) { 125 /* Destroy the contents of the condition structure: */ 126 _thread_queue_init(&(*cond)->c_queue); 127 (*cond)->c_flags = 0; --- 7 unchanged lines hidden (view full) --- 135 136int 137pthread_cond_wait(pthread_cond_t * cond, pthread_mutex_t * mutex) 138{ 139 int rval = 0; 140 int status; 141 142 if (cond == NULL || *cond == NULL) { | 115 break; 116 } 117 118 /* Check for errors: */ 119 if (rval == 0) { 120 /* Destroy the contents of the condition structure: */ 121 _thread_queue_init(&(*cond)->c_queue); 122 (*cond)->c_flags = 0; --- 7 unchanged lines hidden (view full) --- 130 131int 132pthread_cond_wait(pthread_cond_t * cond, pthread_mutex_t * mutex) 133{ 134 int rval = 0; 135 int status; 136 137 if (cond == NULL || *cond == NULL) { |
143 errno = EINVAL; 144 rval = -1; | 138 rval = EINVAL; |
145 } else { 146 /* Block signals: */ 147 _thread_kern_sig_block(&status); 148 149 /* Process according to condition variable type: */ 150 switch ((*cond)->c_type) { 151 /* Fast condition variable: */ 152 case COND_TYPE_FAST: --- 18 unchanged lines hidden (view full) --- 171 172 /* Lock the mutex: */ 173 rval = pthread_mutex_lock(mutex); 174 break; 175 176 /* Trap invalid condition variable types: */ 177 default: 178 /* Return an invalid argument error: */ | 139 } else { 140 /* Block signals: */ 141 _thread_kern_sig_block(&status); 142 143 /* Process according to condition variable type: */ 144 switch ((*cond)->c_type) { 145 /* Fast condition variable: */ 146 case COND_TYPE_FAST: --- 18 unchanged lines hidden (view full) --- 165 166 /* Lock the mutex: */ 167 rval = pthread_mutex_lock(mutex); 168 break; 169 170 /* Trap invalid condition variable types: */ 171 default: 172 /* Return an invalid argument error: */ |
179 errno = EINVAL; 180 rval = -1; | 173 rval = EINVAL; |
181 break; 182 } 183 184 /* Unblock signals: */ 185 _thread_kern_sig_unblock(status); 186 } 187 188 /* Return the completion status: */ 189 return (rval); 190} 191 192int 193pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex, 194 const struct timespec * abstime) 195{ 196 int rval = 0; 197 int status; 198 199 if (cond == NULL || *cond == NULL) { | 174 break; 175 } 176 177 /* Unblock signals: */ 178 _thread_kern_sig_unblock(status); 179 } 180 181 /* Return the completion status: */ 182 return (rval); 183} 184 185int 186pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex, 187 const struct timespec * abstime) 188{ 189 int rval = 0; 190 int status; 191 192 if (cond == NULL || *cond == NULL) { |
200 errno = EINVAL; 201 rval = -1; | 193 rval = EINVAL; |
202 } else { 203 /* Block signals: */ 204 _thread_kern_sig_block(&status); 205 206 /* Process according to condition variable type: */ 207 switch ((*cond)->c_type) { 208 /* Fast condition variable: */ 209 case COND_TYPE_FAST: --- 27 unchanged lines hidden (view full) --- 237 _thread_kern_sig_block(NULL); 238 239 /* Lock the mutex: */ 240 if ((rval = pthread_mutex_lock(mutex)) != 0) { 241 } 242 /* Check if the wait timed out: */ 243 else if (_thread_run->timeout) { 244 /* Return a timeout error: */ | 194 } else { 195 /* Block signals: */ 196 _thread_kern_sig_block(&status); 197 198 /* Process according to condition variable type: */ 199 switch ((*cond)->c_type) { 200 /* Fast condition variable: */ 201 case COND_TYPE_FAST: --- 27 unchanged lines hidden (view full) --- 229 _thread_kern_sig_block(NULL); 230 231 /* Lock the mutex: */ 232 if ((rval = pthread_mutex_lock(mutex)) != 0) { 233 } 234 /* Check if the wait timed out: */ 235 else if (_thread_run->timeout) { 236 /* Return a timeout error: */ |
245 errno = ETIMEDOUT; 246 rval = -1; | 237 rval = ETIMEDOUT; |
247 } 248 } 249 break; 250 251 /* Trap invalid condition variable types: */ 252 default: 253 /* Return an invalid argument error: */ | 238 } 239 } 240 break; 241 242 /* Trap invalid condition variable types: */ 243 default: 244 /* Return an invalid argument error: */ |
254 errno = EINVAL; 255 rval = -1; | 245 rval = EINVAL; |
256 break; 257 } 258 259 /* Unblock signals: */ 260 _thread_kern_sig_unblock(status); 261 } 262 263 /* Return the completion status: */ 264 return (rval); 265} 266 267int 268pthread_cond_signal(pthread_cond_t * cond) 269{ 270 int rval = 0; 271 int status; 272 pthread_t pthread; 273 274 if (cond == NULL || *cond == NULL) { | 246 break; 247 } 248 249 /* Unblock signals: */ 250 _thread_kern_sig_unblock(status); 251 } 252 253 /* Return the completion status: */ 254 return (rval); 255} 256 257int 258pthread_cond_signal(pthread_cond_t * cond) 259{ 260 int rval = 0; 261 int status; 262 pthread_t pthread; 263 264 if (cond == NULL || *cond == NULL) { |
275 errno = EINVAL; 276 rval = -1; | 265 rval = EINVAL; |
277 } else { 278 /* Block signals: */ 279 _thread_kern_sig_block(&status); 280 281 /* Process according to condition variable type: */ 282 switch ((*cond)->c_type) { 283 /* Fast condition variable: */ 284 case COND_TYPE_FAST: 285 /* Bring the next thread off the condition queue: */ 286 if ((pthread = _thread_queue_deq(&(*cond)->c_queue)) != NULL) { 287 /* Allow the thread to run: */ 288 PTHREAD_NEW_STATE(pthread,PS_RUNNING); 289 } 290 break; 291 292 /* Trap invalid condition variable types: */ 293 default: 294 /* Return an invalid argument error: */ | 266 } else { 267 /* Block signals: */ 268 _thread_kern_sig_block(&status); 269 270 /* Process according to condition variable type: */ 271 switch ((*cond)->c_type) { 272 /* Fast condition variable: */ 273 case COND_TYPE_FAST: 274 /* Bring the next thread off the condition queue: */ 275 if ((pthread = _thread_queue_deq(&(*cond)->c_queue)) != NULL) { 276 /* Allow the thread to run: */ 277 PTHREAD_NEW_STATE(pthread,PS_RUNNING); 278 } 279 break; 280 281 /* Trap invalid condition variable types: */ 282 default: 283 /* Return an invalid argument error: */ |
295 errno = EINVAL; 296 rval = -1; | 284 rval = EINVAL; |
297 break; 298 } 299 300 /* Unblock signals: */ 301 _thread_kern_sig_unblock(status); 302 } 303 304 /* Return the completion status: */ --- 23 unchanged lines hidden (view full) --- 328 /* Allow the thread to run: */ 329 PTHREAD_NEW_STATE(pthread,PS_RUNNING); 330 } 331 break; 332 333 /* Trap invalid condition variable types: */ 334 default: 335 /* Return an invalid argument error: */ | 285 break; 286 } 287 288 /* Unblock signals: */ 289 _thread_kern_sig_unblock(status); 290 } 291 292 /* Return the completion status: */ --- 23 unchanged lines hidden (view full) --- 316 /* Allow the thread to run: */ 317 PTHREAD_NEW_STATE(pthread,PS_RUNNING); 318 } 319 break; 320 321 /* Trap invalid condition variable types: */ 322 default: 323 /* Return an invalid argument error: */ |
336 errno = EINVAL; 337 rval = -1; | 324 rval = EINVAL; |
338 break; 339 } 340 341 /* Unblock signals: */ 342 _thread_kern_sig_unblock(status); 343 344 /* Return the completion status: */ 345 return (rval); 346} 347#endif | 325 break; 326 } 327 328 /* Unblock signals: */ 329 _thread_kern_sig_unblock(status); 330 331 /* Return the completion status: */ 332 return (rval); 333} 334#endif |