diff --git a/net/arp/arp_notify.c b/net/arp/arp_notify.c index 9691414e15e..fed64880ce6 100644 --- a/net/arp/arp_notify.c +++ b/net/arp/arp_notify.c @@ -32,7 +32,7 @@ #include -#include +#include #include #include "arp/arp.h" @@ -46,6 +46,7 @@ /* List of tasks waiting for ARP events */ static FAR struct arp_notify_s *g_arp_waiters; +static spinlock_t g_arp_notify_lock = SP_UNLOCKED; /**************************************************************************** * Public Functions @@ -78,10 +79,10 @@ void arp_wait_setup(in_addr_t ipaddr, FAR struct arp_notify_s *notify) /* Add the wait structure to the list with interrupts disabled */ - flags = enter_critical_section(); - notify->nt_flink = g_arp_waiters; - g_arp_waiters = notify; - leave_critical_section(flags); + flags = spin_lock_irqsave(&g_arp_notify_lock); + notify->nt_flink = g_arp_waiters; + g_arp_waiters = notify; + spin_unlock_irqrestore(&g_arp_notify_lock, flags); } /**************************************************************************** @@ -108,7 +109,7 @@ int arp_wait_cancel(FAR struct arp_notify_s *notify) * head of the list). */ - flags = enter_critical_section(); + flags = spin_lock_irqsave(&g_arp_notify_lock); for (prev = NULL, curr = g_arp_waiters; curr && curr != notify; prev = curr, curr = curr->nt_flink) @@ -130,7 +131,7 @@ int arp_wait_cancel(FAR struct arp_notify_s *notify) ret = OK; } - leave_critical_section(flags); + spin_unlock_irqrestore(&g_arp_notify_lock, flags); nxsem_destroy(¬ify->nt_sem); return ret; } @@ -187,7 +188,7 @@ void arp_notify(in_addr_t ipaddr) FAR struct arp_notify_s *curr; irqstate_t flags; - flags = enter_critical_section(); + flags = spin_lock_irqsave_nopreempt(&g_arp_notify_lock); /* Find an entry with the matching IP address in the list of waiters */ @@ -208,7 +209,7 @@ void arp_notify(in_addr_t ipaddr) } } - leave_critical_section(flags); + spin_unlock_irqrestore_nopreempt(&g_arp_notify_lock, flags); } #endif /* CONFIG_NET_ARP_SEND */ diff --git a/net/icmpv6/icmpv6_notify.c b/net/icmpv6/icmpv6_notify.c index 18b29523b97..7361b4a30b5 100644 --- a/net/icmpv6/icmpv6_notify.c +++ b/net/icmpv6/icmpv6_notify.c @@ -33,7 +33,7 @@ #include -#include +#include #include #include "icmpv6/icmpv6.h" @@ -55,6 +55,7 @@ /* List of tasks waiting for Neighbor Discover events */ static struct icmpv6_notify_s *g_icmpv6_waiters; +static spinlock_t g_icmpv6_notify_lock = SP_UNLOCKED; /**************************************************************************** * Private Functions @@ -92,10 +93,10 @@ void icmpv6_wait_setup(const net_ipv6addr_t ipaddr, /* Add the wait structure to the list with interrupts disabled */ - flags = enter_critical_section(); - notify->nt_flink = g_icmpv6_waiters; - g_icmpv6_waiters = notify; - leave_critical_section(flags); + flags = spin_lock_irqsave(&g_icmpv6_notify_lock); + notify->nt_flink = g_icmpv6_waiters; + g_icmpv6_waiters = notify; + spin_unlock_irqrestore(&g_icmpv6_notify_lock, flags); } /**************************************************************************** @@ -123,7 +124,7 @@ int icmpv6_wait_cancel(FAR struct icmpv6_notify_s *notify) * head of the list). */ - flags = enter_critical_section(); + flags = spin_lock_irqsave(&g_icmpv6_notify_lock); for (prev = NULL, curr = g_icmpv6_waiters; curr && curr != notify; prev = curr, curr = curr->nt_flink) @@ -145,7 +146,7 @@ int icmpv6_wait_cancel(FAR struct icmpv6_notify_s *notify) ret = OK; } - leave_critical_section(flags); + spin_unlock_irqrestore(&g_icmpv6_notify_lock, flags); nxsem_destroy(¬ify->nt_sem); return ret; } @@ -201,6 +202,9 @@ int icmpv6_wait(FAR struct icmpv6_notify_s *notify, unsigned int timeout) void icmpv6_notify(net_ipv6addr_t ipaddr) { FAR struct icmpv6_notify_s *curr; + irqstate_t flags; + + flags = spin_lock_irqsave_nopreempt(&g_icmpv6_notify_lock); /* Find an entry with the matching IP address in the list of waiters */ @@ -220,6 +224,8 @@ void icmpv6_notify(net_ipv6addr_t ipaddr) break; } } + + spin_unlock_irqrestore_nopreempt(&g_icmpv6_notify_lock, flags); } #endif /* CONFIG_NET_ICMPv6_NEIGHBOR */ diff --git a/net/icmpv6/icmpv6_rnotify.c b/net/icmpv6/icmpv6_rnotify.c index 06092f78e2f..35ec5375891 100644 --- a/net/icmpv6/icmpv6_rnotify.c +++ b/net/icmpv6/icmpv6_rnotify.c @@ -33,7 +33,7 @@ #include -#include +#include #include #include @@ -59,6 +59,7 @@ /* List of tasks waiting for Neighbor Discover events */ static struct icmpv6_rnotify_s *g_icmpv6_rwaiters; +static spinlock_t g_icmpv6_rnotify_lock = SP_UNLOCKED; /**************************************************************************** * Public Functions @@ -183,10 +184,10 @@ void icmpv6_rwait_setup(FAR struct net_driver_s *dev, /* Add the wait structure to the list with interrupts disabled */ - flags = enter_critical_section(); + flags = spin_lock_irqsave(&g_icmpv6_rnotify_lock); notify->rn_flink = g_icmpv6_rwaiters; - g_icmpv6_rwaiters = notify; - leave_critical_section(flags); + g_icmpv6_rwaiters = notify; + spin_unlock_irqrestore(&g_icmpv6_rnotify_lock, flags); } /**************************************************************************** @@ -216,7 +217,7 @@ int icmpv6_rwait_cancel(FAR struct icmpv6_rnotify_s *notify) * head of the list). */ - flags = enter_critical_section(); + flags = spin_lock_irqsave(&g_icmpv6_rnotify_lock); for (prev = NULL, curr = g_icmpv6_rwaiters; curr && curr != notify; prev = curr, curr = curr->rn_flink) @@ -238,7 +239,7 @@ int icmpv6_rwait_cancel(FAR struct icmpv6_rnotify_s *notify) ret = OK; } - leave_critical_section(flags); + spin_unlock_irqrestore(&g_icmpv6_rnotify_lock, flags); nxsem_destroy(¬ify->rn_sem); return ret; } @@ -296,9 +297,12 @@ int icmpv6_rwait(FAR struct icmpv6_rnotify_s *notify, unsigned int timeout) void icmpv6_rnotify(FAR struct net_driver_s *dev, int result) { FAR struct icmpv6_rnotify_s *curr; + irqstate_t flags; ninfo("Notified\n"); + flags = spin_lock_irqsave_nopreempt(&g_icmpv6_rnotify_lock); + /* Find an entry with the matching device name in the list of waiters */ for (curr = g_icmpv6_rwaiters; curr; curr = curr->rn_flink) @@ -318,6 +322,8 @@ void icmpv6_rnotify(FAR struct net_driver_s *dev, int result) break; } } + + spin_unlock_irqrestore_nopreempt(&g_icmpv6_rnotify_lock, flags); } #endif /* CONFIG_NET_ICMPv6_AUTOCONF */ diff --git a/net/igmp/igmp_timer.c b/net/igmp/igmp_timer.c index 3227a4c32f9..b1187013965 100644 --- a/net/igmp/igmp_timer.c +++ b/net/igmp/igmp_timer.c @@ -50,7 +50,6 @@ #include #include -#include #include #include #include @@ -231,15 +230,8 @@ void igmp_starttimer(FAR struct igmp_group_s *group, uint8_t decisecs) bool igmp_cmptimer(FAR struct igmp_group_s *group, int maxticks) { - irqstate_t flags; int remaining; - /* Disable interrupts so that there is no race condition with the actual - * timer expiration. - */ - - flags = enter_critical_section(); - /* Get the timer remaining on the watchdog. A time of <= zero means that * the watchdog was never started. */ @@ -257,11 +249,9 @@ bool igmp_cmptimer(FAR struct igmp_group_s *group, int maxticks) /* Cancel the watchdog timer and return true */ wd_cancel(&group->wdog); - leave_critical_section(flags); return true; } - leave_critical_section(flags); return false; }