arm: Rename armTickToNs(), etc

This commit is contained in:
plutooo 2018-10-28 17:37:56 +01:00 committed by fincs
parent 436607abef
commit 09a178db70
3 changed files with 16 additions and 6 deletions

View File

@ -27,10 +27,20 @@ static inline u64 armGetSystemTickFreq(void) {
return ret; return ret;
} }
static inline u64 armNsToTick(u64 ns) { /**
* @brief Converts from nanoseconds to CPU ticks unit.
* @param ns Time in nanoseconds.
* @return Time in CPU ticks.
*/
static inline u64 armNsToTicks(u64 ns) {
return (ns * 12) / 625; return (ns * 12) / 625;
} }
static inline u64 armTickToNs(u64 tick) { /**
* @brief Converts from CPU ticks unit to nanoseconds.
* @param tick Time in ticks.
* @return Time in nanoseconds.
*/
static inline u64 armTicksToNs(u64 tick) {
return (tick * 625) / 12; return (tick * 625) / 12;
} }

View File

@ -36,14 +36,14 @@ Result eventWait(Event* t, u64 timeout)
return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); return MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
if (timeout != U64_MAX) if (timeout != U64_MAX)
deadline = armGetSystemTick() + armNsToTick(timeout); // timeout: ns->ticks deadline = armGetSystemTick() + armNsToTicks(timeout); // timeout: ns->ticks
do { do {
do { do {
s64 this_timeout = -1; s64 this_timeout = -1;
if (deadline) { if (deadline) {
this_timeout = deadline - armGetSystemTick(); this_timeout = deadline - armGetSystemTick();
this_timeout = armTickToNs(this_timeout >= 0 ? this_timeout : 0); // ticks->ns this_timeout = armTicksToNs(this_timeout >= 0 ? this_timeout : 0); // ticks->ns
} }
rc = svcWaitSynchronizationSingle(t->revent, this_timeout); rc = svcWaitSynchronizationSingle(t->revent, this_timeout);

View File

@ -6,7 +6,7 @@
void utimerCreate(UsermodeTimer* t, u64 interval, bool start) void utimerCreate(UsermodeTimer* t, u64 interval, bool start)
{ {
t->next_time = 0; t->next_time = 0;
t->interval = armNsToTick(interval); t->interval = armNsToTicks(interval);
if (start) if (start)
utimerStart(t); utimerStart(t);
@ -15,7 +15,7 @@ void utimerCreate(UsermodeTimer* t, u64 interval, bool start)
void utimerStart(UsermodeTimer* t) void utimerStart(UsermodeTimer* t)
{ {
u64 zero = 0; u64 zero = 0;
__atomic_compare_exchange_n(&t->next_time, &zero, armGetSystemTick() + armNsToTick(t->interval), false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); __atomic_compare_exchange_n(&t->next_time, &zero, armGetSystemTick() + armNsToTicks(t->interval), false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
} }
void utimerStop(UsermodeTimer* t) void utimerStop(UsermodeTimer* t)