Skip to content

Commit c41729b

Browse files
committed
Misc adjustments
1 parent 1f4b5cb commit c41729b

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/common/isc_sync.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -813,21 +813,24 @@ int SharedMemoryBase::eventWait(event_t* event, const SLONG value, const SLONG m
813813
struct timespec timer;
814814
if (micro_seconds > 0)
815815
{
816-
#if defined HAVE_CLOCK_GETTIME
816+
#if defined(HAVE_CLOCK_GETTIME)
817817
clock_gettime(CLOCK_REALTIME, &timer);
818-
#else
818+
#elif defined(HAVE_GETTIMEOFDAY)
819819
struct timeval tp;
820820
GETTIMEOFDAY(&tp);
821821
timer.tv_sec = tp.tv_sec;
822822
timer.tv_nsec = tp.tv_usec * 1000;
823+
#else
824+
struct timeb time_buffer;
825+
ftime(&time_buffer);
826+
timer.tv_sec = time_buffer.time;
827+
timer.tv_nsec = time_buffer.millitm * 1000000;
823828
#endif
824-
timer.tv_sec += micro_seconds / 1000000;
825-
timer.tv_nsec += 1000 * (micro_seconds % 1000000);
826-
if (timer.tv_nsec >= 1000000000l)
827-
{
828-
timer.tv_sec++;
829-
timer.tv_nsec -= 1000000000l;
830-
}
829+
const SINT64 BILLION = 1000000000;
830+
const SINT64 nanos = (SINT64) timer.tv_sec * BILLION + timer.tv_nsec +
831+
(SINT64) micro_seconds * 1000;
832+
timer.tv_sec = nanos / BILLION;
833+
timer.tv_nsec = nanos % BILLION;
831834
}
832835

833836
int ret = FB_SUCCESS;

0 commit comments

Comments
 (0)