mirror of
https://github.com/apache/nuttx.git
synced 2026-08-01 20:28:58 +00:00
sched/wdog: fix race condition in wd_gettime()
Move WDOG_ISACTIVE check inside critical section protection to avoid race condition Signed-off-by: chao an <anchao.archer@bytedance.com>
This commit is contained in:
parent
c44834fb92
commit
6300bc5522
1 changed files with 12 additions and 5 deletions
|
|
@ -58,14 +58,21 @@ sclock_t wd_gettime(FAR struct wdog_s *wdog)
|
|||
clock_t expired;
|
||||
sclock_t delay = 0;
|
||||
|
||||
if (wdog && WDOG_ISACTIVE(wdog))
|
||||
if (wdog != NULL)
|
||||
{
|
||||
flags = enter_critical_section();
|
||||
expired = wdog->expired;
|
||||
leave_critical_section(flags);
|
||||
if (WDOG_ISACTIVE(wdog))
|
||||
{
|
||||
expired = wdog->expired;
|
||||
leave_critical_section(flags);
|
||||
|
||||
delay = (sclock_t)(expired - clock_systime_ticks());
|
||||
delay = delay >= 0 ? delay : 0;
|
||||
delay = (sclock_t)(expired - clock_systime_ticks());
|
||||
delay = delay >= 0 ? delay : 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
leave_critical_section(flags);
|
||||
}
|
||||
}
|
||||
|
||||
return delay;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue