From 57e54b399b32c782566f3a984078634d6b4bada1 Mon Sep 17 00:00:00 2001 From: hujun5 Date: Mon, 6 Jan 2025 11:15:45 +0800 Subject: [PATCH] sched: remove all spin_lock_irqsave(NULL) Signed-off-by: hujun5 --- drivers/timers/rpmsg_rtc.c | 11 +++++++++++ include/nuttx/sched.h | 2 ++ sched/clock/clock.h | 2 ++ sched/clock/clock_gettime.c | 8 ++++---- sched/clock/clock_initialize.c | 26 ++++++++++++++------------ sched/clock/clock_settime.c | 8 +++++--- sched/clock/clock_systime_timespec.c | 4 ++-- sched/group/group_create.c | 1 + sched/group/group_exitinfo.c | 6 +++--- sched/group/group_join.c | 4 ++-- sched/group/group_leave.c | 4 ++-- sched/irq/irq_attach.c | 11 ++++++----- sched/irq/irq_chain.c | 10 ++++++++-- sched/mqueue/mq_initialize.c | 2 ++ sched/mqueue/mq_msgfree.c | 8 ++++---- sched/mqueue/mq_send.c | 8 ++++---- sched/mqueue/mqueue.h | 3 +++ sched/signal/sig_default.c | 8 ++++---- sched/signal/sig_findaction.c | 4 ++-- sched/task/task_setup.c | 4 ++-- sched/timer/timer.h | 3 +++ sched/timer/timer_create.c | 8 ++++---- sched/timer/timer_initialize.c | 6 ++++-- sched/timer/timer_release.c | 6 +++--- 24 files changed, 97 insertions(+), 60 deletions(-) diff --git a/drivers/timers/rpmsg_rtc.c b/drivers/timers/rpmsg_rtc.c index 31cff5f16d..68a5c731c5 100644 --- a/drivers/timers/rpmsg_rtc.c +++ b/drivers/timers/rpmsg_rtc.c @@ -308,8 +308,12 @@ static int rpmsg_rtc_ept_cb(FAR struct rpmsg_endpoint *ept, FAR void *data, struct rpmsg_rtc_set_s *msg = data; #ifdef CONFIG_RTC_RPMSG_SYNC_BASETIME + irqstate_t flags; + + flags = spin_lock_irqsave(&g_basetime_lock); g_basetime.tv_sec = msg->base_sec; g_basetime.tv_nsec = msg->base_nsec; + spin_unlock_irqrestore(&g_basetime_lock, flags); #else struct timespec tp; @@ -480,6 +484,7 @@ static int rpmsg_rtc_server_settime(FAR struct rtc_lowerhalf_s *lower, FAR struct rpmsg_rtc_client_s *client; FAR struct list_node *node; struct rpmsg_rtc_set_s msg; + irqstate_t flags; int ret; ret = server->lower->ops->settime(server->lower, rtctime); @@ -500,8 +505,10 @@ static int rpmsg_rtc_server_settime(FAR struct rtc_lowerhalf_s *lower, ret = 1; /* Request the upper half skip clock synchronize */ } + flags = spin_lock_irqsave(&g_basetime_lock); msg.base_sec = g_basetime.tv_sec; msg.base_nsec = g_basetime.tv_nsec; + spin_unlock_irqrestore(&g_basetime_lock, flags); nxmutex_lock(&server->lock); @@ -730,6 +737,7 @@ static void rpmsg_rtc_server_ns_bind(FAR struct rpmsg_device *rdev, FAR struct rpmsg_rtc_client_s *client; struct rpmsg_rtc_set_s msg; struct rtc_time rtctime; + irqstate_t flags; client = kmm_zalloc(sizeof(*client)); if (client == NULL) @@ -753,8 +761,11 @@ static void rpmsg_rtc_server_ns_bind(FAR struct rpmsg_device *rdev, { msg.sec = timegm((FAR struct tm *)&rtctime); msg.nsec = rtctime.tm_nsec; + + flags = spin_lock_irqsave(&g_basetime_lock); msg.base_sec = g_basetime.tv_sec; msg.base_nsec = g_basetime.tv_nsec; + spin_unlock_irqrestore(&g_basetime_lock, flags); msg.header.command = RPMSG_RTC_SYNC; rpmsg_send(&client->ept, &msg, sizeof(msg)); diff --git a/include/nuttx/sched.h b/include/nuttx/sched.h index 916b4e2b82..e2507f9938 100644 --- a/include/nuttx/sched.h +++ b/include/nuttx/sched.h @@ -571,6 +571,8 @@ struct task_group_s /* Virtual memory mapping info ********************************************/ struct mm_map_s tg_mm_map; /* Task group virtual memory mappings */ + + spinlock_t tg_lock; /* lock */ }; /* struct tcb_s *************************************************************/ diff --git a/sched/clock/clock.h b/sched/clock/clock.h index 8c676ec41a..acd076a6de 100644 --- a/sched/clock/clock.h +++ b/sched/clock/clock.h @@ -33,6 +33,7 @@ #include #include +#include /**************************************************************************** * Pre-processor Definitions @@ -66,6 +67,7 @@ extern volatile clock_t g_system_ticks; #ifndef CONFIG_CLOCK_TIMEKEEPING extern struct timespec g_basetime; +extern spinlock_t g_basetime_lock; #endif /**************************************************************************** diff --git a/sched/clock/clock_gettime.c b/sched/clock/clock_gettime.c index f3ee59d135..ebebef61a4 100644 --- a/sched/clock/clock_gettime.c +++ b/sched/clock/clock_gettime.c @@ -58,7 +58,7 @@ static clock_t clock_process_runtime(FAR struct tcb_s *tcb) group = tcb->group; - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&group->tg_lock); sq_for_every(&group->tg_members, curr) { tcb = container_of(curr, struct tcb_s, member); @@ -66,7 +66,7 @@ static clock_t clock_process_runtime(FAR struct tcb_s *tcb) runtime += tcb->run_time; } - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&group->tg_lock, flags); return runtime; # else /* HAVE_GROUP_MEMBERS */ return tcb->run_time; @@ -109,9 +109,9 @@ void nxclock_gettime(clockid_t clock_id, FAR struct timespec *tp) * was last set, this gives us the current time. */ - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&g_basetime_lock); clock_timespec_add(&g_basetime, &ts, tp); - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&g_basetime_lock, flags); #else clock_timekeeping_get_wall_time(tp); #endif diff --git a/sched/clock/clock_initialize.c b/sched/clock/clock_initialize.c index bb1b9f5317..020bb2e9b6 100644 --- a/sched/clock/clock_initialize.c +++ b/sched/clock/clock_initialize.c @@ -56,6 +56,7 @@ volatile clock_t g_system_ticks = INITIAL_SYSTEM_TIMER_TICKS; #ifndef CONFIG_CLOCK_TIMEKEEPING struct timespec g_basetime; +spinlock_t g_basetime_lock = SP_UNLOCKED; #endif /**************************************************************************** @@ -160,7 +161,9 @@ static void clock_inittime(FAR const struct timespec *tp) #ifndef CONFIG_CLOCK_TIMEKEEPING struct timespec ts; + irqstate_t flags; + flags = spin_lock_irqsave(&g_basetime_lock); if (tp) { memcpy(&g_basetime, tp, sizeof(struct timespec)); @@ -170,8 +173,12 @@ static void clock_inittime(FAR const struct timespec *tp) clock_basetime(&g_basetime); } + spin_unlock_irqrestore(&g_basetime_lock, flags); + clock_systime_timespec(&ts); + flags = spin_lock_irqsave(&g_basetime_lock); + /* Adjust base time to hide initial timer ticks. */ g_basetime.tv_sec -= ts.tv_sec; @@ -181,6 +188,8 @@ static void clock_inittime(FAR const struct timespec *tp) g_basetime.tv_nsec += NSEC_PER_SEC; g_basetime.tv_sec--; } + + spin_unlock_irqrestore(&g_basetime_lock, flags); #else clock_inittimekeeping(tp); #endif @@ -266,13 +275,9 @@ void clock_initialize(void) #ifdef CONFIG_RTC void clock_synchronize(FAR const struct timespec *tp) { - irqstate_t flags; - /* Re-initialize the time value to match the RTC */ - flags = enter_critical_section(); clock_inittime(tp); - leave_critical_section(flags); } #endif @@ -319,10 +324,6 @@ void clock_resynchronize(FAR struct timespec *rtc_diff) rtc_diff = &rtc_diff_tmp; } - /* Set the time value to match the RTC */ - - flags = enter_critical_section(); - /* Get RTC time */ ret = clock_basetime(&rtc_time); @@ -334,9 +335,11 @@ void clock_resynchronize(FAR struct timespec *rtc_diff) rtc_diff->tv_sec = 0; rtc_diff->tv_nsec = 0; - goto skip; + return; } + /* Set the time value to match the RTC */ + /* Get the elapsed time since power up (in milliseconds). This is a * bias value that we need to use to correct the base time. */ @@ -348,7 +351,9 @@ void clock_resynchronize(FAR struct timespec *rtc_diff) * was last set, this gives us the current time. */ + flags = spin_lock_irqsave(&g_basetime_lock); clock_timespec_add(&bias, &g_basetime, &curr_ts); + spin_unlock_irqrestore(&g_basetime_lock, flags); /* Check if RTC has advanced past system time. */ @@ -382,9 +387,6 @@ void clock_resynchronize(FAR struct timespec *rtc_diff) atomic_fetch_add((FAR atomic_t *)&g_system_ticks, diff_ticks); #endif } - -skip: - leave_critical_section(flags); } #endif diff --git a/sched/clock/clock_settime.c b/sched/clock/clock_settime.c index e07b4fd941..41017e6964 100644 --- a/sched/clock/clock_settime.c +++ b/sched/clock/clock_settime.c @@ -33,6 +33,7 @@ #include #include +#include #include #include "clock/clock.h" @@ -71,16 +72,17 @@ void nxclock_settime(clockid_t clock_id, FAR const struct timespec *tp) * possible. */ - flags = enter_critical_section(); - /* Get the elapsed time since power up (in milliseconds). This is a * bias value that we need to use to correct the base time. */ clock_systime_timespec(&bias); + + flags = spin_lock_irqsave(&g_basetime_lock); + clock_timespec_subtract(tp, &bias, &g_basetime); - leave_critical_section(flags); + spin_unlock_irqrestore(&g_basetime_lock, flags); /* Setup the RTC (lo- or high-res) */ diff --git a/sched/clock/clock_systime_timespec.c b/sched/clock/clock_systime_timespec.c index 2e60b59a5b..fbb7ed6f14 100644 --- a/sched/clock/clock_systime_timespec.c +++ b/sched/clock/clock_systime_timespec.c @@ -68,9 +68,9 @@ int clock_systime_timespec(FAR struct timespec *ts) up_rtc_gettime(ts); - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&g_basetime_lock); clock_timespec_subtract(ts, &g_basetime, ts); - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&g_basetime_lock, flags); } else { diff --git a/sched/group/group_create.c b/sched/group/group_create.c index bbeb77e5cc..a3c10de1d2 100644 --- a/sched/group/group_create.c +++ b/sched/group/group_create.c @@ -222,6 +222,7 @@ void group_postinitialize(FAR struct task_tcb_s *tcb) DEBUGASSERT(tcb && tcb->cmn.group); group = tcb->cmn.group; + spin_lock_init(&group->tg_lock); /* Allocate mm_map list if required */ diff --git a/sched/group/group_exitinfo.c b/sched/group/group_exitinfo.c index 22987a76b4..e82a72e420 100644 --- a/sched/group/group_exitinfo.c +++ b/sched/group/group_exitinfo.c @@ -70,14 +70,14 @@ int group_exitinfo(pid_t pid, FAR struct binary_s *bininfo) irqstate_t flags; DEBUGASSERT(bininfo != NULL); - flags = spin_lock_irqsave(NULL); + flags = enter_critical_section(); /* Get the TCB associated with the PID */ tcb = nxsched_get_tcb(pid); if (tcb == NULL) { - spin_unlock_irqrestore(NULL, flags); + leave_critical_section(flags); return -ESRCH; } @@ -90,7 +90,7 @@ int group_exitinfo(pid_t pid, FAR struct binary_s *bininfo) group->tg_bininfo = bininfo; - spin_unlock_irqrestore(NULL, flags); + leave_critical_section(flags); return OK; } diff --git a/sched/group/group_join.c b/sched/group/group_join.c index 941d8a5866..8209ba9357 100644 --- a/sched/group/group_join.c +++ b/sched/group/group_join.c @@ -102,9 +102,9 @@ void group_join(FAR struct pthread_tcb_s *tcb) /* Add the member to the group */ - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&group->tg_lock); sq_addfirst(&tcb->cmn.member, &group->tg_members); - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&group->tg_lock, flags); } #endif /* !CONFIG_DISABLE_PTHREAD */ diff --git a/sched/group/group_leave.c b/sched/group/group_leave.c index 8069f94c8b..e5e4c5a706 100644 --- a/sched/group/group_leave.c +++ b/sched/group/group_leave.c @@ -185,9 +185,9 @@ void group_leave(FAR struct tcb_s *tcb) /* Remove the member from group. */ #ifdef HAVE_GROUP_MEMBERS - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&group->tg_lock); sq_rem(&tcb->member, &group->tg_members); - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&group->tg_lock, flags); /* Have all of the members left the group? */ diff --git a/sched/irq/irq_attach.c b/sched/irq/irq_attach.c index 93097ef962..cccd353ca7 100644 --- a/sched/irq/irq_attach.c +++ b/sched/irq/irq_attach.c @@ -36,6 +36,7 @@ * Private Data ****************************************************************************/ +static spinlock_t g_irqlock = SP_UNLOCKED; #ifdef CONFIG_ARCH_MINIMAL_VECTORTABLE_DYNAMIC static int g_irqmap_count = 1; #endif @@ -67,13 +68,13 @@ int irq_to_ndx(int irq) { DEBUGASSERT(g_irqmap_count < CONFIG_ARCH_NUSER_INTERRUPTS); - irqstate_t flags = spin_lock_irqsave(NULL); + irqstate_t flags = spin_lock_irqsave(&g_irqlock); if (g_irqmap[irq] == 0) { g_irqmap[irq] = g_irqmap_count++; } - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&g_irqlock, flags); return g_irqmap[irq]; } #endif @@ -107,7 +108,7 @@ int irq_attach(int irq, xcpt_t isr, FAR void *arg) * to the unexpected interrupt handler. */ - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&g_irqlock); if (isr == NULL) { /* Disable the interrupt if we can before detaching it. We might @@ -141,7 +142,7 @@ int irq_attach(int irq, xcpt_t isr, FAR void *arg) if (is_irqchain(ndx, isr)) { ret = irqchain_attach(ndx, isr, arg); - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&g_irqlock, flags); return ret; } #endif @@ -156,7 +157,7 @@ int irq_attach(int irq, xcpt_t isr, FAR void *arg) g_irqvector[ndx].count = 0; #endif - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&g_irqlock, flags); ret = OK; } diff --git a/sched/irq/irq_chain.c b/sched/irq/irq_chain.c index 0a3e4e0cb9..cb292ac45d 100644 --- a/sched/irq/irq_chain.c +++ b/sched/irq/irq_chain.c @@ -57,6 +57,7 @@ static struct irqchain_s g_irqchainpool[CONFIG_PREALLOC_IRQCHAIN]; */ static sq_queue_t g_irqchainfreelist; +static spinlock_t g_irqchainlock = SP_UNLOCKED; /**************************************************************************** * Private Functions @@ -146,13 +147,16 @@ int irqchain_attach(int ndx, xcpt_t isr, FAR void *arg) { FAR struct irqchain_s *node; FAR struct irqchain_s *curr; + irqstate_t flags; + flags = spin_lock_irqsave(&g_irqchainlock); if (isr != irq_unexpected_isr) { if (g_irqvector[ndx].handler != irqchain_dispatch) { if (sq_count(&g_irqchainfreelist) < 2) { + spin_unlock_irqrestore(&g_irqchainlock, flags); return -ENOMEM; } @@ -170,6 +174,7 @@ int irqchain_attach(int ndx, xcpt_t isr, FAR void *arg) node = (FAR struct irqchain_s *)sq_remfirst(&g_irqchainfreelist); if (node == NULL) { + spin_unlock_irqrestore(&g_irqchainlock, flags); return -ENOMEM; } @@ -190,6 +195,7 @@ int irqchain_attach(int ndx, xcpt_t isr, FAR void *arg) irqchain_detach_all(ndx); } + spin_unlock_irqrestore(&g_irqchainlock, flags); return OK; } @@ -211,7 +217,7 @@ int irqchain_detach(int irq, xcpt_t isr, FAR void *arg) return ndx; } - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&g_irqchainlock); if (g_irqvector[ndx].handler == irqchain_dispatch) { @@ -257,7 +263,7 @@ int irqchain_detach(int irq, xcpt_t isr, FAR void *arg) ret = irq_detach(irq); } - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&g_irqchainlock, flags); } return ret; diff --git a/sched/mqueue/mq_initialize.c b/sched/mqueue/mq_initialize.c index 28691a15ab..6976332799 100644 --- a/sched/mqueue/mq_initialize.c +++ b/sched/mqueue/mq_initialize.c @@ -78,6 +78,8 @@ struct list_node g_msgfree; struct list_node g_msgfreeirq; +spinlock_t g_msgfreelock = SP_UNLOCKED; + #endif /**************************************************************************** diff --git a/sched/mqueue/mq_msgfree.c b/sched/mqueue/mq_msgfree.c index 846218eb1b..23134a497b 100644 --- a/sched/mqueue/mq_msgfree.c +++ b/sched/mqueue/mq_msgfree.c @@ -69,9 +69,9 @@ void nxmq_free_msg(FAR struct mqueue_msg_s *mqmsg) * list from interrupt handlers. */ - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&g_msgfreelock); list_add_tail(&g_msgfree, &mqmsg->node); - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&g_msgfreelock, flags); } /* If this is a message pre-allocated for interrupts, @@ -84,9 +84,9 @@ void nxmq_free_msg(FAR struct mqueue_msg_s *mqmsg) * list from interrupt handlers. */ - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&g_msgfreelock); list_add_tail(&g_msgfreeirq, &mqmsg->node); - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&g_msgfreelock, flags); } /* Otherwise, deallocate it. Note: interrupt handlers diff --git a/sched/mqueue/mq_send.c b/sched/mqueue/mq_send.c index 3c86f12208..241bd3cd25 100644 --- a/sched/mqueue/mq_send.c +++ b/sched/mqueue/mq_send.c @@ -139,9 +139,9 @@ static FAR struct mqueue_msg_s *nxmq_alloc_msg(uint16_t msgsize) /* Try to get the message from the generally available free list. */ - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&g_msgfreelock); mqmsg = (FAR struct mqueue_msg_s *)list_remove_head(&g_msgfree); - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&g_msgfreelock, flags); if (mqmsg == NULL) { /* If we were called from an interrupt handler, then try to get the @@ -153,9 +153,9 @@ static FAR struct mqueue_msg_s *nxmq_alloc_msg(uint16_t msgsize) { /* Try the free list reserved for interrupt handlers */ - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&g_msgfreelock); mqmsg = (FAR struct mqueue_msg_s *)list_remove_head(&g_msgfreeirq); - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&g_msgfreelock, flags); } /* We were not called from an interrupt handler. */ diff --git a/sched/mqueue/mqueue.h b/sched/mqueue/mqueue.h index f47ea8e06d..9499e155e2 100644 --- a/sched/mqueue/mqueue.h +++ b/sched/mqueue/mqueue.h @@ -37,6 +37,7 @@ #include #include +#include #include #if defined(CONFIG_MQ_MAXMSGSIZE) && CONFIG_MQ_MAXMSGSIZE > 0 @@ -101,6 +102,8 @@ EXTERN struct list_node g_msgfree; EXTERN struct list_node g_msgfreeirq; +EXTERN spinlock_t g_msgfreelock; + /**************************************************************************** * Public Function Prototypes ****************************************************************************/ diff --git a/sched/signal/sig_default.c b/sched/signal/sig_default.c index b129c60beb..a2c0143857 100644 --- a/sched/signal/sig_default.c +++ b/sched/signal/sig_default.c @@ -534,9 +534,9 @@ _sa_handler_t nxsig_default(FAR struct tcb_s *tcb, int signo, bool defaction) { /* nxsig_addset() is not atomic (but neither is sigaction()) */ - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&group->tg_lock); nxsig_addset(&group->tg_sigdefault, signo); - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&group->tg_lock, flags); } } @@ -546,9 +546,9 @@ _sa_handler_t nxsig_default(FAR struct tcb_s *tcb, int signo, bool defaction) * atomic (but neither is sigaction()). */ - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&group->tg_lock); nxsig_delset(&group->tg_sigdefault, signo); - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&group->tg_lock, flags); } return handler; diff --git a/sched/signal/sig_findaction.c b/sched/signal/sig_findaction.c index fc519232f7..ddfc777d0d 100644 --- a/sched/signal/sig_findaction.c +++ b/sched/signal/sig_findaction.c @@ -57,7 +57,7 @@ FAR sigactq_t *nxsig_find_action(FAR struct task_group_s *group, int signo) * protection. */ - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&group->tg_lock); /* Search the list for a sigaction on this signal */ @@ -65,7 +65,7 @@ FAR sigactq_t *nxsig_find_action(FAR struct task_group_s *group, int signo) ((sigact) && (sigact->signo != signo)); sigact = sigact->flink); - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&group->tg_lock, flags); } return sigact; diff --git a/sched/task/task_setup.c b/sched/task/task_setup.c index 123af650f4..2fa39a0ef2 100644 --- a/sched/task/task_setup.c +++ b/sched/task/task_setup.c @@ -482,10 +482,10 @@ static int nxthread_setup_scheduler(FAR struct tcb_s *tcb, int priority, /* Add the task to the inactive task list */ - flags = spin_lock_irqsave(NULL); + flags = enter_critical_section(); dq_addfirst((FAR dq_entry_t *)tcb, list_inactivetasks()); tcb->task_state = TSTATE_TASK_INACTIVE; - spin_unlock_irqrestore(NULL, flags); + leave_critical_section(flags); } return ret; diff --git a/sched/timer/timer.h b/sched/timer/timer.h index a4e88bb5c3..4f6fd6e213 100644 --- a/sched/timer/timer.h +++ b/sched/timer/timer.h @@ -35,6 +35,7 @@ #include #include #include +#include #ifndef CONFIG_DISABLE_POSIX_TIMERS @@ -85,6 +86,8 @@ extern volatile sq_queue_t g_freetimers; extern volatile sq_queue_t g_alloctimers; +extern spinlock_t g_locktimers; + /**************************************************************************** * Public Function Prototypes ****************************************************************************/ diff --git a/sched/timer/timer_create.c b/sched/timer/timer_create.c index 57b9800bc3..4f42d8902c 100644 --- a/sched/timer/timer_create.c +++ b/sched/timer/timer_create.c @@ -63,10 +63,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 = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&g_locktimers); ret = (FAR struct posix_timer_s *) sq_remfirst((FAR sq_queue_t *)&g_freetimers); - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&g_locktimers, flags); /* Did we get one? */ @@ -95,9 +95,9 @@ static FAR struct posix_timer_s *timer_allocate(void) /* And add it to the end of the list of allocated timers */ - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&g_locktimers); sq_addlast((FAR sq_entry_t *)ret, (FAR sq_queue_t *)&g_alloctimers); - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&g_locktimers, flags); } return ret; diff --git a/sched/timer/timer_initialize.c b/sched/timer/timer_initialize.c index 56d21c041d..1e6cbb8274 100644 --- a/sched/timer/timer_initialize.c +++ b/sched/timer/timer_initialize.c @@ -66,6 +66,8 @@ volatile sq_queue_t g_freetimers; volatile sq_queue_t g_alloctimers; +spinlock_t g_locktimers = SP_UNLOCKED; + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -173,7 +175,7 @@ FAR struct posix_timer_s *timer_gethandle(timer_t timerid) if (timerid != NULL) { - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&g_locktimers); sq_for_every(&g_alloctimers, entry) { @@ -184,7 +186,7 @@ FAR struct posix_timer_s *timer_gethandle(timer_t timerid) } } - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&g_locktimers, flags); } return timer; diff --git a/sched/timer/timer_release.c b/sched/timer/timer_release.c index 90756ed4be..9a132c403c 100644 --- a/sched/timer/timer_release.c +++ b/sched/timer/timer_release.c @@ -57,7 +57,7 @@ static inline void timer_free(struct posix_timer_s *timer) /* Remove the timer from the allocated list */ - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&g_locktimers); 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 */ @@ -66,14 +66,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); - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&g_locktimers, flags); } else #endif { /* Otherwise, return it to the heap */ - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&g_locktimers, flags); kmm_free(timer); } }