OSR Dev Blog

Simplifying Time Interval Specification
(By: Hector J. Rodriguez | Published: 13-Sep-03| Modified: 13-Sep-03)

Personally, it's never bothered me.  But if you're mathematically challenged (like my boy Peter who has a chart in his office with "milli, micro, nano" written on it and a corresponding string of zeros for each) I can see how having to specify timeout values in NT's standard "100ns intervals" could drive you nuts.

Rob Green, a member of the NTDEV list, provides the following set of macros that'll keep you from having to scratch your head and count zeros ever again.  Using these defintions, all you'll have to do is write:

interval.QuadPart = RELATIVE(SECONDS(5));

And you'll be all set.  Thanks to Rob for his suggestion, and for his permission to share it with you here.

#define ABSOLUTE(wait) (wait)

#define RELATIVE(wait) (-(wait))

#define NANOSECONDS(nanos) \
(((signed __int64)(nanos)) / 100L)

#define MICROSECONDS(micros) \
(((signed __int64)(micros)) * NANOSECONDS(1000L))

#define MILLISECONDS(milli) \
(((signed __int64)(milli)) * MICROSECONDS(1000L))

#define SECONDS(seconds) \
(((signed __int64)(seconds)) * MILLISECONDS(1000L))


This article was printed from OSR Online http://www.osronline.com

Copyright 2017 OSR Open Systems Resources, Inc.