]> git.openfabrics.org - ~shefty/rdma-win.git/commitdiff
Refresh of ucl
authorSean Hefty <sean.hefty@intel.com>
Mon, 28 Jun 2010 21:35:35 +0000 (14:35 -0700)
committerSean Hefty <sean.hefty@intel.com>
Mon, 28 Jun 2010 21:35:35 +0000 (14:35 -0700)
trunk/core/complib/user/cl_timer.c
trunk/inc/user/complib/cl_timer_osd.h

index 37c5448be1d4d24a4cb7fe94001d02d1a97928d5..5cab378aa37041cfb65fc36254b6c9f071b1ef02 100644 (file)
 \r
 \r
 #include "complib/cl_timer.h"\r
\r
 \r
+#define CL_MAX_TIME 0xFFFFFFFF\r
 \r
-static HANDLE\r
-__clear_timer_handle(\r
-       IN      cl_timer_t* const p_timer )\r
-{\r
-       HANDLE timer;\r
-\r
-       EnterCriticalSection( &p_timer->lock );\r
-       timer = p_timer->h_timer;\r
-       p_timer->h_timer = NULL;\r
-       LeaveCriticalSection( &p_timer->lock );\r
-\r
-       return timer;\r
-}\r
 \r
+/*\r
+ * If timeout_time is 0, the timer has been stopped.\r
+ */\r
 static void CALLBACK\r
 __timer_callback( \r
        IN cl_timer_t* const p_timer,\r
        IN BOOLEAN timer_signalled )\r
 {\r
+       uint64_t timeout;\r
        UNUSED_PARAM( timer_signalled );\r
 \r
-       if( !__clear_timer_handle( p_timer ))\r
-               return;\r
-\r
        EnterCriticalSection( &p_timer->cb_lock );\r
-       (p_timer->pfn_callback)( (void*)p_timer->context );\r
+       EnterCriticalSection( &p_timer->lock );\r
+       timeout = p_timer->timeout_time;\r
+       p_timer->timeout_time = 0;\r
+       LeaveCriticalSection( &p_timer->lock );\r
+\r
+       if( timeout )\r
+               (p_timer->pfn_callback)( (void*)p_timer->context );\r
        LeaveCriticalSection( &p_timer->cb_lock );\r
 }\r
 \r
@@ -86,12 +82,11 @@ cl_timer_init(
 \r
        p_timer->pfn_callback = pfn_callback;\r
        p_timer->context = context;\r
-       p_timer->h_timer_queue = CreateTimerQueue();\r
-       if( !p_timer->h_timer_queue )\r
-               return CL_ERROR;\r
-\r
        InitializeCriticalSection( &p_timer->lock );\r
        InitializeCriticalSection( &p_timer->cb_lock );\r
+       if( !CreateTimerQueueTimer( &p_timer->h_timer, NULL, __timer_callback,\r
+               p_timer, CL_MAX_TIME, CL_MAX_TIME, WT_EXECUTEINIOTHREAD ) )\r
+               return CL_ERROR;\r
        return( CL_SUCCESS );\r
 }\r
 \r
@@ -102,12 +97,9 @@ cl_timer_destroy(
 {\r
        CL_ASSERT( p_timer );\r
        \r
-       if( p_timer->h_timer_queue )\r
-       {\r
-               DeleteTimerQueueEx( p_timer->h_timer_queue, INVALID_HANDLE_VALUE );\r
-               DeleteCriticalSection( &p_timer->lock );\r
-               DeleteCriticalSection( &p_timer->cb_lock );\r
-       }\r
+       DeleteTimerQueueTimer( NULL, p_timer->h_timer, INVALID_HANDLE_VALUE );\r
+       DeleteCriticalSection( &p_timer->lock );\r
+       DeleteCriticalSection( &p_timer->cb_lock );\r
 }\r
 \r
 \r
@@ -131,39 +123,35 @@ cl_timer_trim(
        CL_ASSERT( p_timer );\r
        CL_ASSERT( p_timer->pfn_callback );\r
 \r
-       timeout = cl_get_time_stamp() + (((uint64_t)time_ms) * 1000);\r
-\r
        EnterCriticalSection( &p_timer->lock );\r
-       if ( !p_timer->h_timer || timeout < p_timer->timeout_time )\r
+       timeout = cl_get_time_stamp() + (((uint64_t)time_ms) * 1000);\r
+       if ( !p_timer->timeout_time || timeout < p_timer->timeout_time )\r
        {\r
-               if( p_timer->h_timer )\r
-                       DeleteTimerQueueTimer( p_timer->h_timer_queue, p_timer->h_timer, NULL );\r
-\r
-               p_timer->timeout_time = timeout;\r
-               if( !CreateTimerQueueTimer( &p_timer->h_timer, p_timer->h_timer_queue,\r
-                       __timer_callback, p_timer, time_ms, 0, WT_EXECUTEINIOTHREAD ) )\r
-               {\r
-                       p_timer->h_timer = NULL;\r
+               if( ChangeTimerQueueTimer( NULL, p_timer->h_timer, time_ms, CL_MAX_TIME ) )\r
+                       p_timer->timeout_time = timeout;\r
+               else\r
                        status = CL_ERROR;\r
-               }\r
        }\r
        LeaveCriticalSection( &p_timer->lock );\r
        return status;\r
 }\r
 \r
 \r
+/*\r
+ * Acquire cb_lock to ensure that all callbacks have completed.\r
+ */\r
 void\r
 cl_timer_stop(\r
        IN      cl_timer_t* const       p_timer )\r
 {\r
-       HANDLE timer;\r
-\r
        CL_ASSERT( p_timer );\r
 \r
-       timer = __clear_timer_handle( p_timer );\r
-\r
-       if( timer )\r
-               DeleteTimerQueueTimer( p_timer->h_timer_queue, timer, INVALID_HANDLE_VALUE );\r
+       EnterCriticalSection( &p_timer->cb_lock );\r
+       EnterCriticalSection( &p_timer->lock );\r
+       p_timer->timeout_time = 0;\r
+       ChangeTimerQueueTimer( NULL, p_timer->h_timer, CL_MAX_TIME, CL_MAX_TIME );\r
+       LeaveCriticalSection( &p_timer->lock );\r
+       LeaveCriticalSection( &p_timer->cb_lock );\r
 }\r
 \r
 \r
index 370a1755b8a0b556b7c57e76cfd73649d7a8d6d8..a4a119580bcb1bd94daebc5fce975be9dcf97c76 100644 (file)
 \r
 #include "cl_types.h"\r
 \r
-\r
-/* Timer object definition. */\r
 typedef struct _cl_timer\r
 {\r
-       HANDLE                                  h_timer_queue;\r
        HANDLE                                  h_timer;\r
        cl_pfn_timer_callback_t pfn_callback;\r
        const void                              *context;\r