Changeset 1391 for branches/GNU/src/gcc/libobjc/thr.c
- Timestamp:
- Apr 27, 2004, 8:39:34 PM (21 years ago)
- Location:
- branches/GNU/src/gcc
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GNU/src/gcc
- Property svn:ignore
-
old new 26 26 configure.vr 27 27 configure.vrs 28 dir.info 28 29 Makefile 29 dir.info30 30 lost+found 31 31 update.out
-
- Property svn:ignore
-
branches/GNU/src/gcc/libobjc/thr.c
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.1.1.2
r1390 r1391 49 49 so it can implement the NSBecomingMultiThreaded notification. 50 50 */ 51 objc_thread_callback objc_set_thread_callback (objc_thread_callback func)51 objc_thread_callback objc_set_thread_callback (objc_thread_callback func) 52 52 { 53 53 objc_thread_callback temp = _objc_became_multi_threaded; … … 77 77 78 78 static volatile void 79 __objc_thread_detach_function (struct __objc_thread_start_state *istate)79 __objc_thread_detach_function (struct __objc_thread_start_state *istate) 80 80 { 81 81 /* Valid state? */ 82 82 if (istate) { 83 id (*imp) (id,SEL,id);83 id (*imp) (id, SEL, id); 84 84 SEL selector = istate->selector; 85 85 id object = istate->object; … … 87 87 88 88 /* Don't need anymore so free it */ 89 objc_free (istate);89 objc_free (istate); 90 90 91 91 /* Clear out the thread local storage */ 92 objc_thread_set_data (NULL);92 objc_thread_set_data (NULL); 93 93 94 94 /* Check to see if we just became multi threaded */ 95 if (! __objc_is_multi_threaded)95 if (! __objc_is_multi_threaded) 96 96 { 97 97 __objc_is_multi_threaded = 1; … … 99 99 /* Call the hook function */ 100 100 if (_objc_became_multi_threaded != NULL) 101 (*_objc_became_multi_threaded) ();101 (*_objc_became_multi_threaded) (); 102 102 } 103 103 104 104 /* Call the method */ 105 if ((imp = (id (*)(id, SEL, id))objc_msg_lookup(object, selector)))106 (*imp) (object, selector, argument);105 if ((imp = (id (*) (id, SEL, id))objc_msg_lookup (object, selector))) 106 (*imp) (object, selector, argument); 107 107 else 108 objc_error (object, OBJC_ERR_UNIMPLEMENTED,109 "objc_thread_detach called with bad selector.\n");108 objc_error (object, OBJC_ERR_UNIMPLEMENTED, 109 "objc_thread_detach called with bad selector.\n"); 110 110 } 111 111 else 112 objc_error (nil, OBJC_ERR_BAD_STATE,113 "objc_thread_detach called with NULL state.\n");112 objc_error (nil, OBJC_ERR_BAD_STATE, 113 "objc_thread_detach called with NULL state.\n"); 114 114 115 115 /* Exit the thread */ 116 objc_thread_exit ();116 objc_thread_exit (); 117 117 } 118 118 … … 132 132 */ 133 133 objc_thread_t 134 objc_thread_detach (SEL selector, id object, id argument)134 objc_thread_detach (SEL selector, id object, id argument) 135 135 { 136 136 struct __objc_thread_start_state *istate; … … 138 138 139 139 /* Allocate the state structure */ 140 if (! (istate = (struct __objc_thread_start_state *)141 objc_malloc(sizeof(*istate))))140 if (! (istate = (struct __objc_thread_start_state *) 141 objc_malloc (sizeof (*istate)))) 142 142 return NULL; 143 143 … … 148 148 149 149 /* lock access */ 150 objc_mutex_lock (__objc_runtime_mutex);150 objc_mutex_lock (__objc_runtime_mutex); 151 151 152 152 /* Call the backend to spawn the thread */ 153 if ((thread_id = __objc_thread_detach ((void *)__objc_thread_detach_function,154 istate)) == NULL)153 if ((thread_id = __objc_thread_detach ((void *)__objc_thread_detach_function, 154 istate)) == NULL) 155 155 { 156 156 /* failed! */ 157 objc_mutex_unlock (__objc_runtime_mutex);158 objc_free (istate);157 objc_mutex_unlock (__objc_runtime_mutex); 158 objc_free (istate); 159 159 return NULL; 160 160 } … … 162 162 /* Increment our thread counter */ 163 163 __objc_runtime_threads_alive++; 164 objc_mutex_unlock (__objc_runtime_mutex);164 objc_mutex_unlock (__objc_runtime_mutex); 165 165 166 166 return thread_id; … … 169 169 /* Set the current thread's priority. */ 170 170 int 171 objc_thread_set_priority (int priority)171 objc_thread_set_priority (int priority) 172 172 { 173 173 /* Call the backend */ 174 return __objc_thread_set_priority (priority);174 return __objc_thread_set_priority (priority); 175 175 } 176 176 177 177 /* Return the current thread's priority. */ 178 178 int 179 objc_thread_get_priority (void)179 objc_thread_get_priority (void) 180 180 { 181 181 /* Call the backend */ 182 return __objc_thread_get_priority ();182 return __objc_thread_get_priority (); 183 183 } 184 184 … … 189 189 */ 190 190 void 191 objc_thread_yield (void)191 objc_thread_yield (void) 192 192 { 193 193 /* Call the backend */ 194 __objc_thread_yield ();194 __objc_thread_yield (); 195 195 } 196 196 … … 200 200 */ 201 201 int 202 objc_thread_exit (void)202 objc_thread_exit (void) 203 203 { 204 204 /* Decrement our counter of the number of threads alive */ 205 objc_mutex_lock (__objc_runtime_mutex);205 objc_mutex_lock (__objc_runtime_mutex); 206 206 __objc_runtime_threads_alive--; 207 objc_mutex_unlock (__objc_runtime_mutex);207 objc_mutex_unlock (__objc_runtime_mutex); 208 208 209 209 /* Call the backend to terminate the thread */ 210 return __objc_thread_exit ();210 return __objc_thread_exit (); 211 211 } 212 212 … … 216 216 */ 217 217 objc_thread_t 218 objc_thread_id (void)218 objc_thread_id (void) 219 219 { 220 220 /* Call the backend */ 221 return __objc_thread_id ();221 return __objc_thread_id (); 222 222 } 223 223 … … 227 227 */ 228 228 int 229 objc_thread_set_data (void *value)229 objc_thread_set_data (void *value) 230 230 { 231 231 /* Call the backend */ 232 return __objc_thread_set_data (value);232 return __objc_thread_set_data (value); 233 233 } 234 234 … … 237 237 */ 238 238 void * 239 objc_thread_get_data (void)239 objc_thread_get_data (void) 240 240 { 241 241 /* Call the backend */ 242 return __objc_thread_get_data ();242 return __objc_thread_get_data (); 243 243 } 244 244 … … 250 250 */ 251 251 objc_mutex_t 252 objc_mutex_allocate (void)252 objc_mutex_allocate (void) 253 253 { 254 254 objc_mutex_t mutex; 255 255 256 256 /* Allocate the mutex structure */ 257 if (! (mutex = (objc_mutex_t)objc_malloc(sizeof(struct objc_mutex))))257 if (! (mutex = (objc_mutex_t)objc_malloc (sizeof (struct objc_mutex)))) 258 258 return NULL; 259 259 260 260 /* Call backend to create the mutex */ 261 if (__objc_mutex_allocate (mutex))261 if (__objc_mutex_allocate (mutex)) 262 262 { 263 263 /* failed! */ 264 objc_free (mutex);264 objc_free (mutex); 265 265 return NULL; 266 266 } … … 280 280 */ 281 281 int 282 objc_mutex_deallocate (objc_mutex_t mutex)282 objc_mutex_deallocate (objc_mutex_t mutex) 283 283 { 284 284 int depth; 285 285 286 286 /* Valid mutex? */ 287 if (! mutex)287 if (! mutex) 288 288 return -1; 289 289 290 290 /* Acquire lock on mutex */ 291 depth = objc_mutex_lock (mutex);291 depth = objc_mutex_lock (mutex); 292 292 293 293 /* Call backend to destroy mutex */ 294 if (__objc_mutex_deallocate (mutex))294 if (__objc_mutex_deallocate (mutex)) 295 295 return -1; 296 296 297 297 /* Free the mutex structure */ 298 objc_free (mutex);298 objc_free (mutex); 299 299 300 300 /* Return last depth */ … … 309 309 */ 310 310 int 311 objc_mutex_lock (objc_mutex_t mutex)311 objc_mutex_lock (objc_mutex_t mutex) 312 312 { 313 313 objc_thread_t thread_id; … … 315 315 316 316 /* Valid mutex? */ 317 if (! mutex)317 if (! mutex) 318 318 return -1; 319 319 320 320 /* If we already own the lock then increment depth */ 321 thread_id = __objc_thread_id ();321 thread_id = __objc_thread_id (); 322 322 if (mutex->owner == thread_id) 323 323 return ++mutex->depth; 324 324 325 325 /* Call the backend to lock the mutex */ 326 status = __objc_mutex_lock (mutex);326 status = __objc_mutex_lock (mutex); 327 327 328 328 /* Failed? */ … … 341 341 */ 342 342 int 343 objc_mutex_trylock (objc_mutex_t mutex)343 objc_mutex_trylock (objc_mutex_t mutex) 344 344 { 345 345 objc_thread_t thread_id; … … 347 347 348 348 /* Valid mutex? */ 349 if (! mutex)349 if (! mutex) 350 350 return -1; 351 351 352 352 /* If we already own the lock then increment depth */ 353 thread_id = __objc_thread_id ();353 thread_id = __objc_thread_id (); 354 354 if (mutex->owner == thread_id) 355 355 return ++mutex->depth; 356 356 357 357 /* Call the backend to try to lock the mutex */ 358 status = __objc_mutex_trylock (mutex);358 status = __objc_mutex_trylock (mutex); 359 359 360 360 /* Failed? */ … … 376 376 */ 377 377 int 378 objc_mutex_unlock (objc_mutex_t mutex)378 objc_mutex_unlock (objc_mutex_t mutex) 379 379 { 380 380 objc_thread_t thread_id; … … 382 382 383 383 /* Valid mutex? */ 384 if (! mutex)384 if (! mutex) 385 385 return -1; 386 386 387 387 /* If another thread owns the lock then abort */ 388 thread_id = __objc_thread_id ();388 thread_id = __objc_thread_id (); 389 389 if (mutex->owner != thread_id) 390 390 return -1; … … 399 399 400 400 /* Have the backend unlock the mutex */ 401 status = __objc_mutex_unlock (mutex);401 status = __objc_mutex_unlock (mutex); 402 402 403 403 /* Failed? */ … … 415 415 */ 416 416 objc_condition_t 417 objc_condition_allocate (void)417 objc_condition_allocate (void) 418 418 { 419 419 objc_condition_t condition; 420 420 421 421 /* Allocate the condition mutex structure */ 422 if (! (condition =423 (objc_condition_t)objc_malloc(sizeof(struct objc_condition))))422 if (! (condition = 423 (objc_condition_t) objc_malloc (sizeof (struct objc_condition)))) 424 424 return NULL; 425 425 426 426 /* Call the backend to create the condition mutex */ 427 if (__objc_condition_allocate (condition))427 if (__objc_condition_allocate (condition)) 428 428 { 429 429 /* failed! */ 430 objc_free (condition);430 objc_free (condition); 431 431 return NULL; 432 432 } … … 444 444 */ 445 445 int 446 objc_condition_deallocate (objc_condition_t condition)446 objc_condition_deallocate (objc_condition_t condition) 447 447 { 448 448 /* Broadcast the condition */ 449 if (objc_condition_broadcast (condition))449 if (objc_condition_broadcast (condition)) 450 450 return -1; 451 451 452 452 /* Call the backend to destroy */ 453 if (__objc_condition_deallocate (condition))453 if (__objc_condition_deallocate (condition)) 454 454 return -1; 455 455 456 456 /* Free the condition mutex structure */ 457 objc_free (condition);457 objc_free (condition); 458 458 459 459 return 0; … … 461 461 462 462 /* 463 Wait on the condition unlocking the mutex until objc_condition_signal ()464 or objc_condition_broadcast () are called for the same condition. The463 Wait on the condition unlocking the mutex until objc_condition_signal () 464 or objc_condition_broadcast () are called for the same condition. The 465 465 given mutex *must* have the depth set to 1 so that it can be unlocked 466 466 here, so that someone else can lock it and signal/broadcast the condition. … … 469 469 */ 470 470 int 471 objc_condition_wait (objc_condition_t condition, objc_mutex_t mutex)471 objc_condition_wait (objc_condition_t condition, objc_mutex_t mutex) 472 472 { 473 473 objc_thread_t thread_id; 474 474 475 475 /* Valid arguments? */ 476 if (! mutex || !condition)476 if (! mutex || ! condition) 477 477 return -1; 478 478 479 479 /* Make sure we are owner of mutex */ 480 thread_id = __objc_thread_id ();480 thread_id = __objc_thread_id (); 481 481 if (mutex->owner != thread_id) 482 482 return -1; … … 491 491 492 492 /* Call the backend to wait */ 493 __objc_condition_wait (condition, mutex);493 __objc_condition_wait (condition, mutex); 494 494 495 495 /* Make ourselves owner of the mutex */ … … 507 507 */ 508 508 int 509 objc_condition_broadcast (objc_condition_t condition)509 objc_condition_broadcast (objc_condition_t condition) 510 510 { 511 511 /* Valid condition mutex? */ 512 if (! condition)513 return -1; 514 515 return __objc_condition_broadcast (condition);512 if (! condition) 513 return -1; 514 515 return __objc_condition_broadcast (condition); 516 516 } 517 517 … … 523 523 */ 524 524 int 525 objc_condition_signal (objc_condition_t condition)525 objc_condition_signal (objc_condition_t condition) 526 526 { 527 527 /* Valid condition mutex? */ 528 if (! condition)529 return -1; 530 531 return __objc_condition_signal (condition);528 if (! condition) 529 return -1; 530 531 return __objc_condition_signal (condition); 532 532 } 533 533 … … 536 536 from now on. This is used when you are interfacing with some 537 537 external non-objc-based environment/system - you must call 538 objc_thread_add () before an alien thread makes any calls to538 objc_thread_add () before an alien thread makes any calls to 539 539 Objective-C. Do not cause the _objc_became_multi_threaded hook to 540 540 be executed. */ 541 541 void 542 objc_thread_add (void)543 { 544 objc_mutex_lock (__objc_runtime_mutex);542 objc_thread_add (void) 543 { 544 objc_mutex_lock (__objc_runtime_mutex); 545 545 __objc_is_multi_threaded = 1; 546 546 __objc_runtime_threads_alive++; 547 objc_mutex_unlock (__objc_runtime_mutex);547 objc_mutex_unlock (__objc_runtime_mutex); 548 548 } 549 549 … … 551 551 stopped) by some external code will no longer access objc and thus 552 552 can be forgotten by the objc thread system. Call 553 objc_thread_remove () when your alien thread is done with making553 objc_thread_remove () when your alien thread is done with making 554 554 calls to Objective-C. */ 555 555 void 556 objc_thread_remove (void)557 { 558 objc_mutex_lock (__objc_runtime_mutex);556 objc_thread_remove (void) 557 { 558 objc_mutex_lock (__objc_runtime_mutex); 559 559 __objc_runtime_threads_alive--; 560 objc_mutex_unlock (__objc_runtime_mutex);560 objc_mutex_unlock (__objc_runtime_mutex); 561 561 } 562 562 -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.