Changeset 2323 for trunk/libtransmission/platform.c
- Timestamp:
- Jul 10, 2007, 2:00:20 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/platform.c
r2202 r2323 271 271 { 272 272 #ifdef SYS_BEOS 273 #error how is this done in beos273 return acquire_sem_etc( *l, 1, B_RELATIVE_TIMEOUT, 0 ); 274 274 #else 275 275 /* success on zero! */ … … 300 300 { 301 301 #ifdef SYS_BEOS 302 *c = -1; 302 c->sem = create_sem( 1, "" ); 303 c->start = 0; 304 c->end = 0; 303 305 #else 304 306 pthread_cond_init( c, NULL ); … … 309 311 { 310 312 #ifdef SYS_BEOS 311 *c = find_thread( NULL ); 313 /* Keep track of that thread */ 314 acquire_sem( c->sem ); 315 c->threads[c->end] = find_thread( NULL ); 316 c->end = ( c->end + 1 ) % BEOS_MAX_THREADS; 317 assert( c->end != c->start ); /* We hit BEOS_MAX_THREADS, arggh */ 318 release_sem( c->sem ); 319 312 320 release_sem( *l ); 313 suspend_thread( *c );321 suspend_thread( find_thread( NULL ) ); /* Wait for signal */ 314 322 acquire_sem( *l ); 315 *c = -1;316 323 #else 317 324 pthread_cond_wait( c, l ); … … 319 326 } 320 327 328 #ifdef SYS_BEOS 329 static int condTrySignal( tr_cond_t * c ) 330 { 331 if( c->start == c->end ) 332 return 1; 333 334 for( ;; ) 335 { 336 thread_info info; 337 get_thread_info( c->threads[c->start], &info ); 338 if( info.state == B_THREAD_SUSPENDED ) 339 { 340 resume_thread( c->threads[c->start] ); 341 c->start = ( c->start + 1 ) % BEOS_MAX_THREADS; 342 break; 343 } 344 /* The thread is not suspended yet, which can happen since 345 * tr_condWait does not atomically suspends after releasing 346 * the semaphore. Wait a bit and try again. */ 347 snooze( 5000 ); 348 } 349 return 0; 350 } 351 #endif 321 352 void tr_condSignal( tr_cond_t * c ) 322 353 { 323 354 #ifdef SYS_BEOS 324 while( *c != -1 ) 325 { 326 thread_info info; 327 get_thread_info( *c, &info ); 328 if( info.state == B_THREAD_SUSPENDED ) 329 { 330 resume_thread( *c ); 331 break; 332 } 333 snooze( 5000 ); 334 } 355 acquire_sem( c->sem ); 356 condTrySignal( c ); 357 release_sem( c->sem ); 335 358 #else 336 359 pthread_cond_signal( c ); … … 340 363 { 341 364 #ifdef SYS_BEOS 342 #error how is this done in beos 365 acquire_sem( c->sem ); 366 while( !condTrySignal( c ) ); 367 release_sem( c->sem ); 343 368 #else 344 369 pthread_cond_broadcast( c ); … … 349 374 { 350 375 #ifdef SYS_BEOS 351 *c = -1; /* Shut up gcc */376 delete_sem( c->sem ); 352 377 #else 353 378 pthread_cond_destroy( c );
Note: See TracChangeset
for help on using the changeset viewer.