Skip to content

Commit

Permalink
Replace enter_critical_section with spin_irqsave
Browse files Browse the repository at this point in the history
Base on discusion: apache#10981

Signed-off-by: TaiJuWu <[email protected]>
  • Loading branch information
TaiJuWu committed Oct 20, 2023
1 parent 8bdb78b commit 7453fa0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions mm/mm_heap/mm_malloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ static void free_delaylist(FAR struct mm_heap_s *heap)

/* Move the delay list to local */

flags = enter_critical_section();
flags = spin_lock_irqsave(NULL);

tmp = heap->mm_delaylist[up_cpu_index()];
heap->mm_delaylist[up_cpu_index()] = NULL;

leave_critical_section(flags);
spin_unlock_irqrestore(NULL, flags);

/* Test if the delayed is empty */

Expand Down
9 changes: 5 additions & 4 deletions sched/timer/timer_create.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <nuttx/irq.h>
#include <nuttx/wdog.h>
#include <nuttx/kmalloc.h>
#include <nuttx/spinlock.h>

#include "timer/timer.h"

Expand All @@ -59,10 +60,10 @@ static FAR struct posix_timer_s *timer_allocate(void)
/* Try to get a preallocated timer from the free list */

#if CONFIG_PREALLOC_TIMERS > 0
flags = enter_critical_section();
flags = spin_lock_irqsave(NULL);
ret = (FAR struct posix_timer_s *)
sq_remfirst((FAR sq_queue_t *)&g_freetimers);
leave_critical_section(flags);
spin_unlock_irqrestore(NULL, flags);

/* Did we get one? */

Expand Down Expand Up @@ -91,9 +92,9 @@ static FAR struct posix_timer_s *timer_allocate(void)

/* And add it to the end of the list of allocated timers */

flags = enter_critical_section();
flags = spin_lock_irqsave(NULL);
sq_addlast((FAR sq_entry_t *)ret, (FAR sq_queue_t *)&g_alloctimers);
leave_critical_section(flags);
spin_unlock_irqrestore(NULL, flags);
}

return ret;
Expand Down
7 changes: 4 additions & 3 deletions sched/timer/timer_release.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <nuttx/irq.h>
#include <nuttx/queue.h>
#include <nuttx/kmalloc.h>
#include <nuttx/spinlock.h>

#include "timer/timer.h"

Expand All @@ -54,7 +55,7 @@ static inline void timer_free(struct posix_timer_s *timer)

/* Remove the timer from the allocated list */

flags = enter_critical_section();
flags = spin_lock_irqsave(NULL);
sq_rem((FAR sq_entry_t *)timer, (FAR sq_queue_t *)&g_alloctimers);

/* Return it to the free list if it is one of the preallocated timers */
Expand All @@ -63,14 +64,14 @@ static inline void timer_free(struct posix_timer_s *timer)
if ((timer->pt_flags & PT_FLAGS_PREALLOCATED) != 0)
{
sq_addlast((FAR sq_entry_t *)timer, (FAR sq_queue_t *)&g_freetimers);
leave_critical_section(flags);
spin_unlock_irqrestore(NULL, flags);
}
else
#endif
{
/* Otherwise, return it to the heap */

leave_critical_section(flags);
spin_unlock_irqrestore(NULL, flags);
kmm_free(timer);
}
}
Expand Down

0 comments on commit 7453fa0

Please sign in to comment.