Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change rcutils_time_point_value_t type from uint64_t to int64_t #84

Merged
merged 2 commits into from
Feb 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/rcutils/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ extern "C"
#define RCUTILS_NS_TO_US(nanoseconds) (nanoseconds / 1000)

/// A single point in time, measured in nanoseconds since the Unix epoch.
typedef uint64_t rcutils_time_point_value_t;
typedef int64_t rcutils_time_point_value_t;
/// A duration of time, measured in nanoseconds.
typedef int64_t rcutils_duration_value_t;

Expand Down
16 changes: 9 additions & 7 deletions src/time_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ rcutils_system_time_now(rcutils_time_point_value_t * now)
now, RCUTILS_RET_INVALID_ARGUMENT, rcutils_get_default_allocator());
FILETIME ft;
GetSystemTimePreciseAsFileTime(&ft);
ULARGE_INTEGER uli;
uli.LowPart = ft.dwLowDateTime;
uli.HighPart = ft.dwHighDateTime;
LARGE_INTEGER li;
li.LowPart = ft.dwLowDateTime;
li.HighPart = ft.dwHighDateTime;
// Adjust for January 1st, 1970, see:
// https://support.microsoft.com/en-us/kb/167296
uli.QuadPart -= 116444736000000000;
li.QuadPart -= 116444736000000000;
// Convert to nanoseconds from 100's of nanoseconds.
*now = uli.QuadPart * 100;
*now = li.QuadPart * 100;
return RCUTILS_RET_OK;
}

Expand All @@ -61,8 +61,10 @@ rcutils_steady_time_now(rcutils_time_point_value_t * now)
QueryPerformanceFrequency(&cpu_frequency);
QueryPerformanceCounter(&performance_count);
// Convert to nanoseconds before converting from ticks to avoid precision loss.
rcutils_time_point_value_t intermediate = RCUTILS_S_TO_NS(performance_count.QuadPart);
*now = intermediate / cpu_frequency.QuadPart;
uint64_t intermediate = RCUTILS_S_TO_NS(performance_count.QuadPart);
intermediate /= cpu_frequency.QuadPart;
// This conversion will overflow if the PC runs >292 years non-stop
*now = (rcutils_time_point_value_t)intermediate;
return RCUTILS_RET_OK;
}

Expand Down