From: Sean Hefty Date: Mon, 28 Jun 2010 21:35:35 +0000 (-0700) Subject: Refresh of ucl X-Git-Url: https://openfabrics.org/gitweb/?a=commitdiff_plain;h=266618fdab85462d29de35449f232ad515b19392;p=~shefty%2Frdma-win.git Refresh of ucl --- diff --git a/trunk/core/complib/user/cl_timer.c b/trunk/core/complib/user/cl_timer.c index 37c5448b..5cab378a 100644 --- a/trunk/core/complib/user/cl_timer.c +++ b/trunk/core/complib/user/cl_timer.c @@ -32,34 +32,30 @@ #include "complib/cl_timer.h" + +#define CL_MAX_TIME 0xFFFFFFFF -static HANDLE -__clear_timer_handle( - IN cl_timer_t* const p_timer ) -{ - HANDLE timer; - - EnterCriticalSection( &p_timer->lock ); - timer = p_timer->h_timer; - p_timer->h_timer = NULL; - LeaveCriticalSection( &p_timer->lock ); - - return timer; -} +/* + * If timeout_time is 0, the timer has been stopped. + */ static void CALLBACK __timer_callback( IN cl_timer_t* const p_timer, IN BOOLEAN timer_signalled ) { + uint64_t timeout; UNUSED_PARAM( timer_signalled ); - if( !__clear_timer_handle( p_timer )) - return; - EnterCriticalSection( &p_timer->cb_lock ); - (p_timer->pfn_callback)( (void*)p_timer->context ); + EnterCriticalSection( &p_timer->lock ); + timeout = p_timer->timeout_time; + p_timer->timeout_time = 0; + LeaveCriticalSection( &p_timer->lock ); + + if( timeout ) + (p_timer->pfn_callback)( (void*)p_timer->context ); LeaveCriticalSection( &p_timer->cb_lock ); } @@ -86,12 +82,11 @@ cl_timer_init( p_timer->pfn_callback = pfn_callback; p_timer->context = context; - p_timer->h_timer_queue = CreateTimerQueue(); - if( !p_timer->h_timer_queue ) - return CL_ERROR; - InitializeCriticalSection( &p_timer->lock ); InitializeCriticalSection( &p_timer->cb_lock ); + if( !CreateTimerQueueTimer( &p_timer->h_timer, NULL, __timer_callback, + p_timer, CL_MAX_TIME, CL_MAX_TIME, WT_EXECUTEINIOTHREAD ) ) + return CL_ERROR; return( CL_SUCCESS ); } @@ -102,12 +97,9 @@ cl_timer_destroy( { CL_ASSERT( p_timer ); - if( p_timer->h_timer_queue ) - { - DeleteTimerQueueEx( p_timer->h_timer_queue, INVALID_HANDLE_VALUE ); - DeleteCriticalSection( &p_timer->lock ); - DeleteCriticalSection( &p_timer->cb_lock ); - } + DeleteTimerQueueTimer( NULL, p_timer->h_timer, INVALID_HANDLE_VALUE ); + DeleteCriticalSection( &p_timer->lock ); + DeleteCriticalSection( &p_timer->cb_lock ); } @@ -131,39 +123,35 @@ cl_timer_trim( CL_ASSERT( p_timer ); CL_ASSERT( p_timer->pfn_callback ); - timeout = cl_get_time_stamp() + (((uint64_t)time_ms) * 1000); - EnterCriticalSection( &p_timer->lock ); - if ( !p_timer->h_timer || timeout < p_timer->timeout_time ) + timeout = cl_get_time_stamp() + (((uint64_t)time_ms) * 1000); + if ( !p_timer->timeout_time || timeout < p_timer->timeout_time ) { - if( p_timer->h_timer ) - DeleteTimerQueueTimer( p_timer->h_timer_queue, p_timer->h_timer, NULL ); - - p_timer->timeout_time = timeout; - if( !CreateTimerQueueTimer( &p_timer->h_timer, p_timer->h_timer_queue, - __timer_callback, p_timer, time_ms, 0, WT_EXECUTEINIOTHREAD ) ) - { - p_timer->h_timer = NULL; + if( ChangeTimerQueueTimer( NULL, p_timer->h_timer, time_ms, CL_MAX_TIME ) ) + p_timer->timeout_time = timeout; + else status = CL_ERROR; - } } LeaveCriticalSection( &p_timer->lock ); return status; } +/* + * Acquire cb_lock to ensure that all callbacks have completed. + */ void cl_timer_stop( IN cl_timer_t* const p_timer ) { - HANDLE timer; - CL_ASSERT( p_timer ); - timer = __clear_timer_handle( p_timer ); - - if( timer ) - DeleteTimerQueueTimer( p_timer->h_timer_queue, timer, INVALID_HANDLE_VALUE ); + EnterCriticalSection( &p_timer->cb_lock ); + EnterCriticalSection( &p_timer->lock ); + p_timer->timeout_time = 0; + ChangeTimerQueueTimer( NULL, p_timer->h_timer, CL_MAX_TIME, CL_MAX_TIME ); + LeaveCriticalSection( &p_timer->lock ); + LeaveCriticalSection( &p_timer->cb_lock ); } diff --git a/trunk/inc/user/complib/cl_timer_osd.h b/trunk/inc/user/complib/cl_timer_osd.h index 370a1755..a4a11958 100644 --- a/trunk/inc/user/complib/cl_timer_osd.h +++ b/trunk/inc/user/complib/cl_timer_osd.h @@ -38,11 +38,8 @@ #include "cl_types.h" - -/* Timer object definition. */ typedef struct _cl_timer { - HANDLE h_timer_queue; HANDLE h_timer; cl_pfn_timer_callback_t pfn_callback; const void *context;