Skip to content

fix(osx): consolidate error checks in alt_clock_gettime for clarity #4803

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
14 changes: 11 additions & 3 deletions src/clock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,17 @@ int alt_clock_gettime (int clock_id, timespec *ts)
{
clock_serv_t cclock;
mach_timespec_t mts;
host_get_clock_service (mach_host_self (), clock_id, &cclock);
clock_get_time (cclock, &mts);
mach_port_deallocate (mach_task_self (), cclock);
kern_return_t kr;

kr = host_get_clock_service (mach_host_self (), clock_id, &cclock);
if (kr == KERN_SUCCESS) {
kr = clock_get_time (cclock, &mts);
mach_port_deallocate (mach_task_self (), cclock);
}

if (kr != KERN_SUCCESS)
return -1;

ts->tv_sec = mts.tv_sec;
ts->tv_nsec = mts.tv_nsec;
return 0;
Expand Down
Loading