1
0
mirror of https://github.com/wjwwood/serial.git synced 2026-01-23 04:04:54 +08:00

Rename now function to timespec_now and timeout_time to expiry, for greater clarity.

This commit is contained in:
Mike Purvis 2013-10-28 20:22:55 -04:00
parent dc693e150f
commit 566e00a7c2
2 changed files with 10 additions and 10 deletions

View File

@ -58,8 +58,8 @@ public:
uint32_t remaining(); uint32_t remaining();
private: private:
static timespec now(); static timespec timespec_now();
timespec timeout_time; timespec expiry;
}; };
class serial::Serial::SerialImpl { class serial::Serial::SerialImpl {

View File

@ -52,21 +52,21 @@ using serial::IOException;
MillisecondTimer::MillisecondTimer (const uint32_t millis) MillisecondTimer::MillisecondTimer (const uint32_t millis)
: timeout_time(now()) : expiry(timespec_now())
{ {
int64_t tv_nsec = timeout_time.tv_nsec + (millis * 1e6); int64_t tv_nsec = expiry.tv_nsec + (millis * 1e6);
if (tv_nsec > 1e9) { if (tv_nsec > 1e9) {
timeout_time.tv_nsec = tv_nsec % (int)1e6; expiry.tv_nsec = tv_nsec % (int)1e6;
timeout_time.tv_sec += tv_nsec / (int)1e6; expiry.tv_sec += tv_nsec / (int)1e6;
} }
} }
uint32_t uint32_t
MillisecondTimer::remaining () MillisecondTimer::remaining ()
{ {
timespec now_time(now()); timespec now(timespec_now());
int64_t millis = (timeout_time.tv_sec - now_time.tv_sec) * 1e3; int64_t millis = (expiry.tv_sec - now.tv_sec) * 1e3;
millis += (timeout_time.tv_nsec - now_time.tv_nsec) / 1e6; millis += (expiry.tv_nsec - now.tv_nsec) / 1e6;
if (millis <= 0) { if (millis <= 0) {
throw TimerExpiredException(); throw TimerExpiredException();
} }
@ -74,7 +74,7 @@ MillisecondTimer::remaining ()
} }
timespec timespec
MillisecondTimer::now () MillisecondTimer::timespec_now ()
{ {
timespec time; timespec time;
# ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time # ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time