mirror of
https://github.com/apache/nuttx.git
synced 2026-05-22 22:20:01 +08:00
sched/hrtimer: inline hrtimer_start.
This commit inlined the `hrtimer_start` to allow the compiler to optimize at least 1 branch in hrtimer_start. Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
This commit is contained in:
committed by
Donny(董九柱)
parent
fe184f79f3
commit
7b67055150
+16
-2
@@ -207,9 +207,23 @@ int hrtimer_cancel_sync(FAR hrtimer_t *hrtimer);
|
||||
* OK on success; a negated errno value on failure.
|
||||
****************************************************************************/
|
||||
|
||||
int hrtimer_start_absolute(FAR hrtimer_t *hrtimer, hrtimer_entry_t func,
|
||||
uint64_t expired);
|
||||
|
||||
static inline_function
|
||||
int hrtimer_start(FAR hrtimer_t *hrtimer, hrtimer_entry_t func,
|
||||
uint64_t expired,
|
||||
enum hrtimer_mode_e mode);
|
||||
uint64_t expired, enum hrtimer_mode_e mode)
|
||||
{
|
||||
/* In most cases, the mode can be evaluated at compile time.
|
||||
* The compiler will optimize the code to avoid the branch.
|
||||
*/
|
||||
|
||||
uint64_t next_expired = mode == HRTIMER_MODE_ABS ? expired :
|
||||
clock_systime_nsec() +
|
||||
(expired <= HRTIMER_MAX_DELAY ?
|
||||
expired : HRTIMER_MAX_DELAY);
|
||||
return hrtimer_start_absolute(hrtimer, func, next_expired);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: hrtimer_gettime
|
||||
|
||||
@@ -36,18 +36,17 @@
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: hrtimer_start
|
||||
* Name: hrtimer_start_absolute
|
||||
*
|
||||
* Description:
|
||||
* Start a high-resolution timer to expire after a specified duration
|
||||
* in nanoseconds, either as an absolute or relative time.
|
||||
* in nanoseconds.
|
||||
*
|
||||
* Input Parameters:
|
||||
* hrtimer - Pointer to the hrtimer structure.
|
||||
* func - Expiration callback function.
|
||||
* expired - Expiration time in nanoseconds. Interpretation
|
||||
* depends on mode.
|
||||
* mode - Timer mode (HRTIMER_MODE_ABS or HRTIMER_MODE_REL).
|
||||
*
|
||||
* Returned Value:
|
||||
* OK (0) on success, or a negated errno value on failure.
|
||||
@@ -60,26 +59,12 @@
|
||||
* nanoseconds from the current time.
|
||||
****************************************************************************/
|
||||
|
||||
int hrtimer_start(FAR hrtimer_t *hrtimer, hrtimer_entry_t func,
|
||||
uint64_t expired,
|
||||
enum hrtimer_mode_e mode)
|
||||
int hrtimer_start_absolute(FAR hrtimer_t *hrtimer, hrtimer_entry_t func,
|
||||
uint64_t expired)
|
||||
{
|
||||
uint64_t next_expired;
|
||||
irqstate_t flags;
|
||||
int ret = OK;
|
||||
|
||||
/* Compute absolute expiration time */
|
||||
|
||||
if (mode == HRTIMER_MODE_ABS)
|
||||
{
|
||||
next_expired = expired;
|
||||
}
|
||||
else
|
||||
{
|
||||
expired = expired <= HRTIMER_MAX_DELAY ? expired : HRTIMER_MAX_DELAY;
|
||||
next_expired = clock_systime_nsec() + expired;
|
||||
}
|
||||
|
||||
DEBUGASSERT(hrtimer != NULL);
|
||||
|
||||
/* Acquire the lock and seize the ownership of the hrtimer queue. */
|
||||
@@ -96,7 +81,7 @@ int hrtimer_start(FAR hrtimer_t *hrtimer, hrtimer_entry_t func,
|
||||
}
|
||||
|
||||
hrtimer->func = func;
|
||||
hrtimer->expired = next_expired;
|
||||
hrtimer->expired = expired;
|
||||
|
||||
/* Insert the timer into the hrtimer queue. */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user