Changeset 2577 for trunk/libtransmission/platform.c
- Timestamp:
- Jul 31, 2007, 7:56:40 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/platform.c
r2576 r2577 59 59 #ifdef SYS_BEOS 60 60 thread_id thread; 61 #elif defined(WIN32) 62 HANDLE thread; 61 63 #else 62 64 pthread_t thread; … … 65 67 }; 66 68 67 static void 69 #ifdef WIN32 70 #define ThreadFuncReturnType unsigned WINAPI 71 #else 72 #define ThreadFuncReturnType void 73 #endif 74 75 static ThreadFuncReturnType 68 76 ThreadFunc( void * _t ) 69 77 { … … 80 88 t->func( t->arg ); 81 89 tr_dbg( "Thread '%s' exited", name ); 90 82 91 tr_free( name ); 92 93 #ifdef WIN32 94 _endthreadex( 0 ); 95 return 0; 96 #endif 83 97 } 84 98 … … 96 110 t->thread = spawn_thread( (void*)ThreadFunc, name, B_NORMAL_PRIORITY, t ); 97 111 resume_thread( t->thread ); 112 #elif defined(WIN32) 113 t->thread = (HANDLE) _beginthreadex( NULL, 0, &ThreadFunc, NULL, 0, NULL ); 98 114 #else 99 115 pthread_create( &t->thread, NULL, (void * (*) (void *)) ThreadFunc, t ); … … 111 127 long exit; 112 128 wait_for_thread( t->thread, &exit ); 129 #elif defined(WIN32) 130 WaitForSingleObject(thread->handle, INFINITE); 131 CloseHandle( t->thread ); 113 132 #else 114 133 pthread_join( t->thread, NULL ); … … 131 150 #ifdef SYS_BEOS 132 151 sem_id lock; 152 #elif defined(WIN32) 153 CRITICAL_SECTION lock; 133 154 #else 134 155 pthread_mutex_t lock; … … 143 164 #ifdef SYS_BEOS 144 165 l->lock = create_sem( 1, "" ); 166 #elif defined(WIN32) 167 InitializeCriticalSection( &l->lock ); 145 168 #else 146 169 pthread_mutex_init( &l->lock, NULL ); … … 155 178 #ifdef SYS_BEOS 156 179 delete_sem( l->lock ); 180 #elif defined(WIN32) 181 DeleteCriticalSection( &l->lock ); 157 182 #else 158 183 pthread_mutex_destroy( &l->lock ); … … 162 187 163 188 int 164 tr_lockTryLock( tr_lock_t * l ) 189 tr_lockTryLock( tr_lock_t * l ) /* success on zero! */ 165 190 { 166 191 #ifdef SYS_BEOS 167 192 return acquire_sem_etc( l->lock, 1, B_RELATIVE_TIMEOUT, 0 ); 168 #else 169 /* success on zero! */ 193 #elif defined(WIN32) 194 return !TryEnterCriticalSection( &l->lock ); 195 #else 170 196 return pthread_mutex_trylock( &l->lock ); 171 197 #endif … … 177 203 #ifdef SYS_BEOS 178 204 acquire_sem( l->lock ); 205 #elif defined(WIN32) 206 EnterCriticalSection( &l->lock ); 179 207 #else 180 208 pthread_mutex_lock( &l->lock ); … … 187 215 #ifdef SYS_BEOS 188 216 release_sem( l->lock ); 217 #elif defined(WIN32) 218 DeleteCriticalSection( &l->lock ); 189 219 #else 190 220 pthread_mutex_unlock( &l->lock ); … … 312 342 thread_id theads[BEOS_MAX_THREADS]; 313 343 int start, end; 344 #elif defined(WIN32) 345 CONDITION_VARIABLE cond; 314 346 #else 315 347 pthread_cond_t cond; … … 325 357 c->start = 0; 326 358 c->end = 0; 359 #elif defined(WIN32) 360 InitializeConditionVariable( &c->cond ); 327 361 #else 328 362 pthread_cond_init( &c->cond, NULL ); … … 344 378 suspend_thread( find_thread( NULL ) ); /* Wait for signal */ 345 379 acquire_sem( *l ); 380 #elif defined(WIN32) 381 SleepConditionVariableCS( &c->cond, &l->lock, INFINITE ); 346 382 #else 347 383 pthread_cond_wait( &c->cond, &l->lock ); … … 379 415 condTrySignal( c ); 380 416 release_sem( c->sem ); 417 #elif defined(WIN32) 418 WakeConditionVariable( &c->cond ); 381 419 #else 382 420 pthread_cond_signal( &c->cond ); … … 389 427 while( !condTrySignal( c ) ); 390 428 release_sem( c->sem ); 429 #elif defined(WIN32) 430 WakeAllConditionVariable( &c->cond ); 391 431 #else 392 432 pthread_cond_broadcast( &c->cond ); … … 399 439 #ifdef SYS_BEOS 400 440 delete_sem( c->sem ); 441 #elif defined(WIN32) 442 /* a no-op, apparently */ 401 443 #else 402 444 pthread_cond_destroy( &c->cond );
Note: See TracChangeset
for help on using the changeset viewer.