From 5f3efe434b0ee51877969bc5b2a32e75b02e331a Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 28 Feb 2008 16:40:31 +0000 Subject: [PATCH] better win32 thread support --- libtransmission/platform.c | 26 +++++++++++--------------- libtransmission/transmission.c | 2 +- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/libtransmission/platform.c b/libtransmission/platform.c index e6b9a438b..7d7b1a98a 100644 --- a/libtransmission/platform.c +++ b/libtransmission/platform.c @@ -95,16 +95,10 @@ struct tr_thread void (* func ) ( void * ); void * arg; const char * name; - -#ifdef __BEOS__ - thread_id thread; -#elif defined(WIN32) - HANDLE thread; - unsigned int thread_id; -#else - pthread_t thread; + tr_thread_id thread; +#ifdef WIN32 + HANDLE thread_handle; #endif - }; int @@ -147,18 +141,20 @@ tr_threadNew( void (*func)(void *), const char * name ) { tr_thread * t = tr_new0( tr_thread, 1 ); - t->func = func; - t->arg = arg; - t->name = name; #ifdef __BEOS__ t->thread = spawn_thread( (void*)ThreadFunc, name, B_NORMAL_PRIORITY, t ); resume_thread( t->thread ); #elif defined(WIN32) - t->thread = (HANDLE) _beginthreadex( NULL, 0, &ThreadFunc, t, 0, &t->thread_id ); + unsigned id; + t->thread_handle = (HANDLE) _beginthreadex( NULL, 0, &ThreadFunc, t, 0, &id ); + t->thread = (DWORD) id; #else pthread_create( &t->thread, NULL, (void * (*) (void *)) ThreadFunc, t ); #endif + t->func = func; + t->arg = arg; + t->name = name; return t; } @@ -172,8 +168,8 @@ tr_threadJoin( tr_thread * t ) long exit; wait_for_thread( t->thread, &exit ); #elif defined(WIN32) - WaitForSingleObject( t->thread, INFINITE ); - CloseHandle( t->thread ); + WaitForSingleObject( t->thread_handle, INFINITE ); + CloseHandle( t->thread_handle ); #else pthread_join( t->thread, NULL ); #endif diff --git a/libtransmission/transmission.c b/libtransmission/transmission.c index bc64fcd0c..a978213a7 100644 --- a/libtransmission/transmission.c +++ b/libtransmission/transmission.c @@ -212,7 +212,7 @@ tr_globalUnlock( struct tr_handle * handle ) int tr_globalIsLocked( const struct tr_handle * handle ) { - return tr_lockHave( handle->lock ); + return handle && tr_lockHave( handle->lock ); } /***********************************************************************