diff mbox

complib/cl_timer.c: fixing cl_timer calculation

Message ID 4C7287C8.1040106@dev.mellanox.co.il (mailing list archive)
State Not Applicable, archived
Headers show

Commit Message

Yevgeny Kliteynik Aug. 23, 2010, 2:38 p.m. UTC
None
diff mbox

Patch

diff --git a/opensm/complib/cl_timer.c b/opensm/complib/cl_timer.c
index 2acdb51..09a5584 100644
--- a/opensm/complib/cl_timer.c
+++ b/opensm/complib/cl_timer.c
@@ -299,7 +299,8 @@  cl_status_t cl_timer_start(IN cl_timer_t * const p_timer,
 {
 	struct timeval curtime;
 	cl_list_item_t *p_list_item;
-	uint32_t delta_time = time_ms;
+	uint32_t delta_time_sec = time_ms / 1000;
+	uint32_t delta_time_usec = (time_ms % 1000) * 1000;

 	CL_ASSERT(p_timer);
 	CL_ASSERT(p_timer->state == CL_INITIALIZED);
@@ -324,9 +325,10 @@  cl_status_t cl_timer_start(IN cl_timer_t * const p_timer,
 	/* if (delta_time < 1000.0) {delta_time = 1000;} */

 	/* Calculate the timeout. */
-	p_timer->timeout.tv_sec = curtime.tv_sec + (delta_time / 1000);
+	p_timer->timeout.tv_sec = curtime.tv_sec + delta_time_sec +
+		((curtime.tv_usec + delta_time_usec) / 1000000);
 	p_timer->timeout.tv_nsec =
-	    (curtime.tv_usec + ((delta_time % 1000) * 1000)) * 1000;
+	    ((curtime.tv_usec + delta_time_usec) % 1000000) * 1000;

 	/* Add the timer to the queue. */
 	if (cl_is_qlist_empty(&gp_timer_prov->queue)) {