[Openib-windows] [PATCH] don't deadlock cl_timer_stop when called from timer callback (was RE: Complib changes to support OpenSM in OpenIB)

Fab Tillier ftillier at silverstorm.com
Wed Aug 31 13:12:46 PDT 2005


> From: Eitan Zahavi [mailto:eitan at mellanox.co.il]
> Sent: Tuesday, August 23, 2005 11:09 PM
> 
> Fab Tillier wrote:
> > I think we can do something a little smarter in the implementation without
> > adding a new API - if we record what thread context we are in before
> > invoking the user callback (with GetCurrentThreadId).  We can then check to
> > see if we are in the same thread when we invoke start, and not invoke stop
> > at all.  I'm at IDF until Thursday, but I'll try to get something coded up
> > so you can try it.  If you code it yourselves before I get back in the
> > office, please send the patch so I don't duplicate the effort.
>
> This is a nice idea. We can wait for your return to the office. So we
> will wait for your patch.

Here's a patch for the timer.  The code stores the thread ID of any callback
thread, and checks it in cl_timer_stop and skips canceling the timer if in the
timer callback.

Let me know if it works properly for you.

Thanks,

- Fab

Index: core/complib/user/cl_timer.c
===================================================================
--- core/complib/user/cl_timer.c	(revision 52)
+++ core/complib/user/cl_timer.c	(working copy)
@@ -44,8 +44,11 @@
 	UNUSED_PARAM( timer_signalled );
 
 	p_timer->timeout_time = 0;
+	p_timer->thread_id = GetCurrentThreadId();
 
 	(p_timer->pfn_callback)( (void*)p_timer->context );
+
+	p_timer->thread_id = 0;
 }
 
 
@@ -55,6 +58,7 @@
 {
 	p_timer->h_timer = NULL;
 	p_timer->timeout_time = 0;
+	p_timer->thread_id = 0;
 }
 
 
@@ -134,7 +138,7 @@
 {
 	CL_ASSERT( p_timer );
 
-	if( p_timer->h_timer )
+	if( p_timer->h_timer && p_timer->thread_id != GetCurrentThreadId() )
 	{
 		/* Make sure we block until the timer is cancelled. */
 		DeleteTimerQueueTimer( NULL, p_timer->h_timer,
INVALID_HANDLE_VALUE );
Index: inc/user/complib/cl_timer_osd.h
===================================================================
--- inc/user/complib/cl_timer_osd.h	(revision 52)
+++ inc/user/complib/cl_timer_osd.h	(working copy)
@@ -46,6 +46,7 @@
 	cl_pfn_timer_callback_t	pfn_callback;
 	const void				*context;
 	uint64_t				timeout_time;
+	DWORD					thread_id;
 
 } cl_timer_t;





More information about the ofw mailing list