mirror of
https://github.com/apache/nuttx.git
synced 2026-05-20 04:16:35 +08:00
sched/hrtimer: Fix the functional correctness issue in hrtimer_start.
This commit fixed the functional correctness issue in hrtimer_start by adding HRTIMER_MAX_DELAY fr the HRTIMER_MODE_REL. Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
This commit is contained in:
committed by
GUIDINGLI
parent
a6d64a1a83
commit
0048a5c21b
@@ -36,6 +36,18 @@
|
||||
#include <stdint.h>
|
||||
#include <sys/tree.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* The maximum delay tick should be INT64_MAX. However, if there are expired
|
||||
* hrtimer in the queue, HRTIMER_TIME_BEFORE/AFTER might be incorrect, so we
|
||||
* limited the delay to INT64_MAX >> 1, assuming all expired hrtimer can be
|
||||
* processed within HRTIMER_MAX_DELAY.
|
||||
*/
|
||||
|
||||
#define HRTIMER_MAX_DELAY (INT64_MAX >> 1)
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
@@ -64,9 +64,22 @@ int hrtimer_start(FAR hrtimer_t *hrtimer, hrtimer_entry_t func,
|
||||
uint64_t expired,
|
||||
enum hrtimer_mode_e mode)
|
||||
{
|
||||
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);
|
||||
|
||||
/* Protect container manipulation with spinlock and disable interrupts */
|
||||
@@ -82,22 +95,8 @@ int hrtimer_start(FAR hrtimer_t *hrtimer, hrtimer_entry_t func,
|
||||
hrtimer_remove(hrtimer);
|
||||
}
|
||||
|
||||
hrtimer->func = func;
|
||||
|
||||
/* Compute absolute expiration time */
|
||||
|
||||
if (mode == HRTIMER_MODE_ABS)
|
||||
{
|
||||
hrtimer->expired = expired;
|
||||
}
|
||||
else
|
||||
{
|
||||
hrtimer->expired = clock_systime_nsec() + expired;
|
||||
}
|
||||
|
||||
/* Ensure expiration time does not overflow */
|
||||
|
||||
DEBUGASSERT(hrtimer->expired >= expired);
|
||||
hrtimer->func = func;
|
||||
hrtimer->expired = next_expired;
|
||||
|
||||
/* Insert the timer into the container */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user