From 5f7ea668d6d4c96d9e0efea21ac5e300fda552ad Mon Sep 17 00:00:00 2001 From: rpj Date: Tue, 8 Jan 2002 02:21:06 +0000 Subject: * mutex.c (pthread_mutex_trylock): use ptw32_interlocked_compare_exchange function pointer rather than ptw32_InterlockedCompareExchange() directly to retain portability to non-iX86 processors, e.g. WinCE etc. The pointer will point to the native OS version of InterlockedCompareExchange() if the OS supports it (see ChangeLog entry of 2001-10-17). --- mutex.c | 60 ++++++++++++++++++++++++++++++------------------------------ 1 file changed, 30 insertions(+), 30 deletions(-) (limited to 'mutex.c') diff --git a/mutex.c b/mutex.c index 7a232c5..d1d7aad 100644 --- a/mutex.c +++ b/mutex.c @@ -699,12 +699,12 @@ pthread_mutex_unlock(pthread_mutex_t *mutex) { mx->ownerThread = NULL; - if( InterlockedDecrement( &mx->lock_idx ) >= 0 ) - { - /* Someone is waiting on that mutex */ - ReleaseSemaphore( mx->wait_sema, 1, NULL ); - } - } + if( InterlockedDecrement( &mx->lock_idx ) >= 0 ) + { + /* Someone is waiting on that mutex */ + ReleaseSemaphore( mx->wait_sema, 1, NULL ); + } + } } else { @@ -745,35 +745,35 @@ pthread_mutex_trylock(pthread_mutex_t *mutex) if (result == 0) { - - if( PTW32_MUTEX_LOCK_IDX_INIT == ptw32_InterlockedCompareExchange( - &mx->lock_idx, 0, PTW32_MUTEX_LOCK_IDX_INIT ) ) - { - mx->recursive_count = 1; - mx->ownerThread = (mx->kind != PTHREAD_MUTEX_FAST_NP - ? pthread_self() - : (pthread_t) PTW32_MUTEX_OWNER_ANONYMOUS); - } - + if ( (PTW32_INTERLOCKED_LONG) PTW32_MUTEX_LOCK_IDX_INIT == + ptw32_interlocked_compare_exchange((PTW32_INTERLOCKED_LPLONG) &mx->lock_idx, + (PTW32_INTERLOCKED_LONG) 0, + (PTW32_INTERLOCKED_LONG) PTW32_MUTEX_LOCK_IDX_INIT)) + { + mx->recursive_count = 1; + mx->ownerThread = (mx->kind != PTHREAD_MUTEX_FAST_NP + ? pthread_self() + : (pthread_t) PTW32_MUTEX_OWNER_ANONYMOUS); + } else - { - if( mx->kind != PTHREAD_MUTEX_FAST_NP && - pthread_equal( mx->ownerThread, pthread_self() ) ) - { - if( mx->kind == PTHREAD_MUTEX_RECURSIVE_NP ) + { + if( mx->kind != PTHREAD_MUTEX_FAST_NP && + pthread_equal( mx->ownerThread, pthread_self() ) ) { - mx->recursive_count++; + if( mx->kind == PTHREAD_MUTEX_RECURSIVE_NP ) + { + mx->recursive_count++; + } + else + { + result = EDEADLK; + } } - else + else { - result = EDEADLK; + result = EBUSY; } - } - else - { - result = EBUSY; - } - } + } } return(result); -- cgit v1.2.3