diff --git a/util/goodies.h b/util/goodies.h index 38e10b48e39..55dd4b89bf1 100644 --- a/util/goodies.h +++ b/util/goodies.h @@ -176,11 +176,12 @@ namespace mongo { inline void sleepmillis(int s) { boost::xtime xt; boost::xtime_get(&xt, boost::TIME_UTC); - if( s >= 1000 ) { - xt.sec += s/1000; - s-=1000; - } - xt.nsec += s * 1000000; + xt.sec += ( s / 1000 ); + xt.nsec += ( s % 1000 ) * 1000000; + if ( xt.nsec >= 1000000000 ) { + xt.nsec -= 1000000000; + xt.sec++; + } boost::thread::sleep(xt); } // note this wraps