mirror of
https://github.com/apache/nuttx.git
synced 2026-08-08 22:17:18 +00:00
net: replace critical_section with spin lock
so as to better support multi-core scenarios Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
This commit is contained in:
parent
fc0647491b
commit
9dab103fa0
4 changed files with 35 additions and 32 deletions
|
|
@ -32,7 +32,7 @@
|
|||
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <nuttx/irq.h>
|
||||
#include <nuttx/spinlock.h>
|
||||
#include <nuttx/net/net.h>
|
||||
|
||||
#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 */
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@
|
|||
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <nuttx/irq.h>
|
||||
#include <nuttx/spinlock.h>
|
||||
#include <nuttx/net/net.h>
|
||||
|
||||
#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 */
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@
|
|||
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <nuttx/irq.h>
|
||||
#include <nuttx/spinlock.h>
|
||||
#include <nuttx/net/net.h>
|
||||
#include <nuttx/net/netdev.h>
|
||||
|
||||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -50,7 +50,6 @@
|
|||
#include <debug.h>
|
||||
|
||||
#include <nuttx/wdog.h>
|
||||
#include <nuttx/irq.h>
|
||||
#include <nuttx/wqueue.h>
|
||||
#include <nuttx/net/netconfig.h>
|
||||
#include <nuttx/net/net.h>
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue