[components][sal]replace netdev's spin_lock_irqsave to spin_lock

netdev的函数不会在中断中调用,无需关中断
This commit is contained in:
zms123456 2024-09-14 05:32:35 +08:00 committed by GitHub
parent fb02e7934d
commit 140ca0d2ff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 17 additions and 23 deletions

View File

@ -55,7 +55,6 @@ static RT_DEFINE_SPINLOCK(_spinlock);
*/
int netdev_register(struct netdev *netdev, const char *name, void *user_data)
{
rt_base_t level;
rt_uint16_t flags_mask;
rt_uint16_t index;
@ -103,7 +102,7 @@ int netdev_register(struct netdev *netdev, const char *name, void *user_data)
/* initialize current network interface device single list */
rt_slist_init(&(netdev->list));
level = rt_spin_lock_irqsave(&_spinlock);
rt_spin_lock(&_spinlock);
if (netdev_list == RT_NULL)
{
@ -115,7 +114,7 @@ int netdev_register(struct netdev *netdev, const char *name, void *user_data)
rt_slist_append(&(netdev_list->list), &(netdev->list));
}
rt_spin_unlock_irqrestore(&_spinlock, level);
rt_spin_unlock(&_spinlock);
if (netdev_default == RT_NULL)
{
@ -146,7 +145,6 @@ int netdev_register(struct netdev *netdev, const char *name, void *user_data)
*/
int netdev_unregister(struct netdev *netdev)
{
rt_base_t level;
rt_slist_t *node = RT_NULL;
struct netdev *cur_netdev = RT_NULL;
@ -157,7 +155,7 @@ int netdev_unregister(struct netdev *netdev)
return -RT_ERROR;
}
level = rt_spin_lock_irqsave(&_spinlock);
rt_spin_lock(&_spinlock);
for (node = &(netdev_list->list); node; node = rt_slist_next(node))
{
@ -188,7 +186,7 @@ int netdev_unregister(struct netdev *netdev)
break;
}
}
rt_spin_unlock_irqrestore(&_spinlock, level);
rt_spin_unlock(&_spinlock);
#if defined(SAL_USING_AF_NETLINK)
rtnl_ip_notify(netdev, RTM_DELLINK);
@ -233,7 +231,6 @@ void netdev_set_register_callback(netdev_callback_fn register_callback)
*/
struct netdev *netdev_get_first_by_flags(uint16_t flags)
{
rt_base_t level;
rt_slist_t *node = RT_NULL;
struct netdev *netdev = RT_NULL;
@ -242,19 +239,19 @@ struct netdev *netdev_get_first_by_flags(uint16_t flags)
return RT_NULL;
}
level = rt_spin_lock_irqsave(&_spinlock);
rt_spin_lock(&_spinlock);
for (node = &(netdev_list->list); node; node = rt_slist_next(node))
{
netdev = rt_slist_entry(node, struct netdev, list);
if (netdev && (netdev->flags & flags) != 0)
{
rt_spin_unlock_irqrestore(&_spinlock, level);
rt_spin_unlock(&_spinlock);
return netdev;
}
}
rt_spin_unlock_irqrestore(&_spinlock, level);
rt_spin_unlock(&_spinlock);
return RT_NULL;
}
@ -270,7 +267,6 @@ struct netdev *netdev_get_first_by_flags(uint16_t flags)
*/
struct netdev *netdev_get_by_ipaddr(ip_addr_t *ip_addr)
{
rt_base_t level;
rt_slist_t *node = RT_NULL;
struct netdev *netdev = RT_NULL;
@ -279,19 +275,19 @@ struct netdev *netdev_get_by_ipaddr(ip_addr_t *ip_addr)
return RT_NULL;
}
level = rt_spin_lock_irqsave(&_spinlock);
rt_spin_lock(&_spinlock);
for (node = &(netdev_list->list); node; node = rt_slist_next(node))
{
netdev = rt_slist_entry(node, struct netdev, list);
if (netdev && ip_addr_cmp(&(netdev->ip_addr), ip_addr))
{
rt_spin_unlock_irqrestore(&_spinlock, level);
rt_spin_unlock(&_spinlock);
return netdev;
}
}
rt_spin_unlock_irqrestore(&_spinlock, level);
rt_spin_unlock(&_spinlock);
return RT_NULL;
}
@ -307,7 +303,6 @@ struct netdev *netdev_get_by_ipaddr(ip_addr_t *ip_addr)
*/
struct netdev *netdev_get_by_name(const char *name)
{
rt_base_t level;
rt_slist_t *node = RT_NULL;
struct netdev *netdev = RT_NULL;
@ -316,19 +311,19 @@ struct netdev *netdev_get_by_name(const char *name)
return RT_NULL;
}
level = rt_spin_lock_irqsave(&_spinlock);
rt_spin_lock(&_spinlock);
for (node = &(netdev_list->list); node; node = rt_slist_next(node))
{
netdev = rt_slist_entry(node, struct netdev, list);
if (netdev && (rt_strncmp(netdev->name, name, rt_strlen(name) < RT_NAME_MAX ? rt_strlen(name) : RT_NAME_MAX) == 0))
{
rt_spin_unlock_irqrestore(&_spinlock, level);
rt_spin_unlock(&_spinlock);
return netdev;
}
}
rt_spin_unlock_irqrestore(&_spinlock, level);
rt_spin_unlock(&_spinlock);
return RT_NULL;
}
@ -345,7 +340,6 @@ struct netdev *netdev_get_by_name(const char *name)
*/
struct netdev *netdev_get_by_family(int family)
{
rt_base_t level;
rt_slist_t *node = RT_NULL;
struct netdev *netdev = RT_NULL;
struct sal_proto_family *pf = RT_NULL;
@ -355,7 +349,7 @@ struct netdev *netdev_get_by_family(int family)
return RT_NULL;
}
level = rt_spin_lock_irqsave(&_spinlock);
rt_spin_lock(&_spinlock);
for (node = &(netdev_list->list); node; node = rt_slist_next(node))
{
@ -363,7 +357,7 @@ struct netdev *netdev_get_by_family(int family)
pf = (struct sal_proto_family *) netdev->sal_user_data;
if (pf && pf->skt_ops && pf->family == family && netdev_is_up(netdev))
{
rt_spin_unlock_irqrestore(&_spinlock, level);
rt_spin_unlock(&_spinlock);
return netdev;
}
}
@ -374,12 +368,12 @@ struct netdev *netdev_get_by_family(int family)
pf = (struct sal_proto_family *) netdev->sal_user_data;
if (pf && pf->skt_ops && pf->sec_family == family && netdev_is_up(netdev))
{
rt_spin_unlock_irqrestore(&_spinlock, level);
rt_spin_unlock(&_spinlock);
return netdev;
}
}
rt_spin_unlock_irqrestore(&_spinlock, level);
rt_spin_unlock(&_spinlock);
return RT_NULL;
}