mirror of
https://github.com/apache/nuttx.git
synced 2026-08-08 05:57:16 +00:00
esp32s3/rt_timer: Adjust spinlock position to avoid deadlock
This commit is contained in:
parent
f4485a58e3
commit
a774587088
1 changed files with 16 additions and 14 deletions
|
|
@ -369,11 +369,8 @@ static void start_rt_timer(struct rt_timer_s *timer,
|
|||
uint64_t timeout,
|
||||
bool repeat)
|
||||
{
|
||||
irqstate_t flags;
|
||||
struct esp32s3_rt_priv_s *priv = &g_rt_priv;
|
||||
|
||||
flags = spin_lock_irqsave(&priv->lock);
|
||||
|
||||
/* Only idle timer can be started */
|
||||
|
||||
if (timer->state == RT_TIMER_IDLE)
|
||||
|
|
@ -437,8 +434,6 @@ static void start_rt_timer(struct rt_timer_s *timer,
|
|||
{
|
||||
tmrwarn("Timer not in idle mode. Only idle timer can be started!\n");
|
||||
}
|
||||
|
||||
spin_unlock_irqrestore(&priv->lock, flags);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
|
@ -458,11 +453,8 @@ static void start_rt_timer(struct rt_timer_s *timer,
|
|||
|
||||
static void stop_rt_timer(struct rt_timer_s *timer)
|
||||
{
|
||||
irqstate_t flags;
|
||||
struct esp32s3_rt_priv_s *priv = &g_rt_priv;
|
||||
|
||||
flags = spin_lock_irqsave(&priv->lock);
|
||||
|
||||
/* "start" function can set the timer's repeat flag, and "stop" function
|
||||
* should remove this flag.
|
||||
*/
|
||||
|
|
@ -507,8 +499,6 @@ static void stop_rt_timer(struct rt_timer_s *timer)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
spin_unlock_irqrestore(&priv->lock, flags);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
|
@ -572,6 +562,10 @@ static int rt_timer_thread(int argc, char *argv[])
|
|||
kmm_free(timer);
|
||||
}
|
||||
|
||||
/* Enter critical section for next scanning list */
|
||||
|
||||
flags = spin_lock_irqsave(&priv->lock);
|
||||
|
||||
if (raw_state == RT_TIMER_TIMEOUT)
|
||||
{
|
||||
/* Check if the timer is in "repeat" mode */
|
||||
|
|
@ -581,10 +575,6 @@ static int rt_timer_thread(int argc, char *argv[])
|
|||
start_rt_timer(timer, timer->timeout, true);
|
||||
}
|
||||
}
|
||||
|
||||
/* Enter critical section for next scanning list */
|
||||
|
||||
flags = spin_lock_irqsave(&priv->lock);
|
||||
}
|
||||
|
||||
spin_unlock_irqrestore(&priv->lock, flags);
|
||||
|
|
@ -754,9 +744,16 @@ void esp32s3_rt_timer_start(struct rt_timer_s *timer,
|
|||
uint64_t timeout,
|
||||
bool repeat)
|
||||
{
|
||||
irqstate_t flags;
|
||||
struct esp32s3_rt_priv_s *priv = &g_rt_priv;
|
||||
|
||||
flags = spin_lock_irqsave(&priv->lock);
|
||||
|
||||
stop_rt_timer(timer);
|
||||
|
||||
start_rt_timer(timer, timeout, repeat);
|
||||
|
||||
spin_unlock_irqrestore(&priv->lock, flags);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
|
@ -775,7 +772,12 @@ void esp32s3_rt_timer_start(struct rt_timer_s *timer,
|
|||
|
||||
void esp32s3_rt_timer_stop(struct rt_timer_s *timer)
|
||||
{
|
||||
irqstate_t flags;
|
||||
struct esp32s3_rt_priv_s *priv = &g_rt_priv;
|
||||
|
||||
flags = spin_lock_irqsave(&priv->lock);
|
||||
stop_rt_timer(timer);
|
||||
spin_unlock_irqrestore(&priv->lock, flags);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue