Skip to content

Commit

Permalink
Fixed Darwin Semaphore's millis to nanos convert.
Browse files Browse the repository at this point in the history
  • Loading branch information
juhalaukkanen committed Jan 19, 2015
1 parent 7d1be98 commit 64dec2e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions common/src/Utilities/Darwin/DarwinSemaphore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ bool Threading::Semaphore::WaitWithoutYield(const wxTimeSpan& timeout)

// on x86 platforms, mach_absolute_time() returns nanoseconds
// TODO(aktau): on iOS a scale value from mach_timebase_info will be necessary
u64 delta = (u64) timeout.GetMilliseconds().GetValue();
u64 const kOneThousand = 1000;
u64 const kOneBillion = kOneThousand * kOneThousand * kOneThousand;
u64 const delta = timeout.GetMilliseconds().GetValue() * (kOneThousand * kOneThousand);
mach_timespec_t ts;
kern_return_t kr = KERN_ABORTED;
for (u64 now = mach_absolute_time(), deadline = now + delta;
Expand All @@ -120,8 +122,8 @@ bool Threading::Semaphore::WaitWithoutYield(const wxTimeSpan& timeout)
}

u64 timeleft = deadline - now;
ts.tv_sec = timeleft / 1000000000ULL;
ts.tv_nsec = timeleft % 1000000000ULL;
ts.tv_sec = timeleft / kOneBillion;
ts.tv_nsec = timeleft % kOneBillion;

// possible return values of semaphore_timedwait() (from XNU sources):
// internal kernel val -> return value
Expand Down

0 comments on commit 64dec2e

Please sign in to comment.