summaryrefslogtreecommitdiff
path: root/components/net
diff options
context:
space:
mode:
Diffstat (limited to 'components/net')
-rw-r--r--components/net/lwip/port/ethernetif.c13
-rw-r--r--components/net/lwip/port/netif/ethernetif.h2
-rw-r--r--components/net/lwip/port/sys_arch.c6
-rw-r--r--components/net/netdev/src/netdev.c35
-rw-r--r--components/net/sal/impl/af_inet_lwip.c6
5 files changed, 35 insertions, 27 deletions
diff --git a/components/net/lwip/port/ethernetif.c b/components/net/lwip/port/ethernetif.c
index 85d8dba0cb..b60d40e53a 100644
--- a/components/net/lwip/port/ethernetif.c
+++ b/components/net/lwip/port/ethernetif.c
@@ -564,6 +564,7 @@ rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_
return -RT_ERROR;
}
+ rt_spin_lock_init(&(dev->spinlock));
/* set netif */
dev->netif = netif;
dev->flags = flags;
@@ -838,13 +839,13 @@ rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up)
RT_ASSERT(dev != RT_NULL);
- level = rt_hw_interrupt_disable();
+ level = rt_spin_lock_irqsave(&(dev->spinlock));
dev->link_changed = 0x01;
if (up == RT_TRUE)
dev->link_status = 0x01;
else
dev->link_status = 0x00;
- rt_hw_interrupt_enable(level);
+ rt_spin_unlock_irqrestore(&(dev->spinlock), level);
/* post message to ethernet thread */
return rt_mb_send(&eth_rx_thread_mb, (rt_ubase_t)dev);
@@ -912,10 +913,10 @@ static void eth_rx_thread_entry(void* parameter)
{
int status;
- level = rt_hw_interrupt_disable();
+ level = rt_spin_lock_irqsave(&(device->spinlock));
status = device->link_status;
device->link_changed = 0x00;
- rt_hw_interrupt_enable(level);
+ rt_spin_unlock_irqrestore(&(device->spinlock), level);
if (status)
netifapi_netif_set_link_up(device->netif);
@@ -923,10 +924,10 @@ static void eth_rx_thread_entry(void* parameter)
netifapi_netif_set_link_down(device->netif);
}
- level = rt_hw_interrupt_disable();
+ level = rt_spin_lock_irqsave(&(device->spinlock));
/* 'rx_notice' will be modify in the interrupt or here */
device->rx_notice = RT_FALSE;
- rt_hw_interrupt_enable(level);
+ rt_spin_unlock_irqrestore(&(device->spinlock), level);
/* receive all of buffer */
while (1)
diff --git a/components/net/lwip/port/netif/ethernetif.h b/components/net/lwip/port/netif/ethernetif.h
index 64501de67c..767a18f50c 100644
--- a/components/net/lwip/port/netif/ethernetif.h
+++ b/components/net/lwip/port/netif/ethernetif.h
@@ -42,6 +42,8 @@ struct eth_device
rt_uint8_t link_status;
rt_uint8_t rx_notice;
+ struct rt_spinlock spinlock;
+
/* eth device interface */
struct pbuf* (*eth_rx)(rt_device_t dev);
rt_err_t (*eth_tx)(rt_device_t dev, struct pbuf* p);
diff --git a/components/net/lwip/port/sys_arch.c b/components/net/lwip/port/sys_arch.c
index 4a952cd493..7b845fc028 100644
--- a/components/net/lwip/port/sys_arch.c
+++ b/components/net/lwip/port/sys_arch.c
@@ -511,16 +511,18 @@ sys_thread_t sys_thread_new(const char *name,
return t;
}
+static RT_DEFINE_SPINLOCK(_spinlock);
+
sys_prot_t sys_arch_protect(void)
{
rt_base_t level;
- level = rt_hw_interrupt_disable(); /* disable interrupt */
+ level = rt_spin_lock_irqsave(&_spinlock); /* disable interrupt */
return level;
}
void sys_arch_unprotect(sys_prot_t pval)
{
- rt_hw_interrupt_enable(pval); /* enable interrupt */
+ rt_spin_unlock_irqrestore(&_spinlock, pval); /* enable interrupt */
}
void sys_arch_assert(const char *file, int line)
diff --git a/components/net/netdev/src/netdev.c b/components/net/netdev/src/netdev.c
index eca32f71a1..569ba27040 100644
--- a/components/net/netdev/src/netdev.c
+++ b/components/net/netdev/src/netdev.c
@@ -34,6 +34,7 @@ struct netdev *netdev_default = RT_NULL;
/* The global network register callback */
static netdev_callback_fn g_netdev_register_callback = RT_NULL;
static netdev_callback_fn g_netdev_default_change_callback = RT_NULL;
+static RT_DEFINE_SPINLOCK(_spinlock);
/**
* This function will register network interface device and
@@ -96,7 +97,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_hw_interrupt_disable();
+ level = rt_spin_lock_irqsave(&_spinlock);
if (netdev_list == RT_NULL)
{
@@ -108,7 +109,7 @@ int netdev_register(struct netdev *netdev, const char *name, void *user_data)
rt_slist_append(&(netdev_list->list), &(netdev->list));
}
- rt_hw_interrupt_enable(level);
+ rt_spin_unlock_irqrestore(&_spinlock, level);
if (netdev_default == RT_NULL)
{
@@ -146,7 +147,7 @@ int netdev_unregister(struct netdev *netdev)
return -RT_ERROR;
}
- level = rt_hw_interrupt_disable();
+ level = rt_spin_lock_irqsave(&_spinlock);
for (node = &(netdev_list->list); node; node = rt_slist_next(node))
{
@@ -169,7 +170,7 @@ int netdev_unregister(struct netdev *netdev)
break;
}
}
- rt_hw_interrupt_enable(level);
+ rt_spin_unlock_irqrestore(&_spinlock, level);
if (netdev_default == RT_NULL)
{
@@ -219,19 +220,19 @@ struct netdev *netdev_get_first_by_flags(uint16_t flags)
return RT_NULL;
}
- level = rt_hw_interrupt_disable();
+ level = rt_spin_lock_irqsave(&_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_hw_interrupt_enable(level);
+ rt_spin_unlock_irqrestore(&_spinlock, level);
return netdev;
}
}
- rt_hw_interrupt_enable(level);
+ rt_spin_unlock_irqrestore(&_spinlock, level);
return RT_NULL;
}
@@ -256,19 +257,19 @@ struct netdev *netdev_get_by_ipaddr(ip_addr_t *ip_addr)
return RT_NULL;
}
- level = rt_hw_interrupt_disable();
+ level = rt_spin_lock_irqsave(&_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_hw_interrupt_enable(level);
+ rt_spin_unlock_irqrestore(&_spinlock, level);
return netdev;
}
}
- rt_hw_interrupt_enable(level);
+ rt_spin_unlock_irqrestore(&_spinlock, level);
return RT_NULL;
}
@@ -293,19 +294,19 @@ struct netdev *netdev_get_by_name(const char *name)
return RT_NULL;
}
- level = rt_hw_interrupt_disable();
+ level = rt_spin_lock_irqsave(&_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(netdev->name) < RT_NAME_MAX ? rt_strlen(netdev->name) : RT_NAME_MAX) == 0))
{
- rt_hw_interrupt_enable(level);
+ rt_spin_unlock_irqrestore(&_spinlock, level);
return netdev;
}
}
- rt_hw_interrupt_enable(level);
+ rt_spin_unlock_irqrestore(&_spinlock, level);
return RT_NULL;
}
@@ -332,7 +333,7 @@ struct netdev *netdev_get_by_family(int family)
return RT_NULL;
}
- level = rt_hw_interrupt_disable();
+ level = rt_spin_lock_irqsave(&_spinlock);
for (node = &(netdev_list->list); node; node = rt_slist_next(node))
{
@@ -340,7 +341,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_hw_interrupt_enable(level);
+ rt_spin_unlock_irqrestore(&_spinlock, level);
return netdev;
}
}
@@ -351,12 +352,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_hw_interrupt_enable(level);
+ rt_spin_unlock_irqrestore(&_spinlock, level);
return netdev;
}
}
- rt_hw_interrupt_enable(level);
+ rt_spin_unlock_irqrestore(&_spinlock, level);
return RT_NULL;
}
diff --git a/components/net/sal/impl/af_inet_lwip.c b/components/net/sal/impl/af_inet_lwip.c
index 37da37b137..fa015fd14e 100644
--- a/components/net/sal/impl/af_inet_lwip.c
+++ b/components/net/sal/impl/af_inet_lwip.c
@@ -79,6 +79,8 @@ struct lwip_sock {
};
#endif /* LWIP_VERSION >= 0x20100ff */
+static RT_DEFINE_SPINLOCK(_spinlock);
+
extern struct lwip_sock *lwip_tryget_socket(int s);
static void event_callback(struct netconn *conn, enum netconn_evt evt, u16_t len)
@@ -262,7 +264,7 @@ static int inet_poll(struct dfs_file *file, struct rt_pollreq *req)
rt_poll_add(&sock->wait_head, req);
- level = rt_hw_interrupt_disable();
+ level = rt_spin_lock_irqsave(&_spinlock);
#if LWIP_VERSION >= 0x20100ff
if ((void*)(sock->lastdata.pbuf) || sock->rcvevent)
@@ -282,7 +284,7 @@ static int inet_poll(struct dfs_file *file, struct rt_pollreq *req)
/* clean error event */
sock->errevent = 0;
}
- rt_hw_interrupt_enable(level);
+ rt_spin_unlock_irqrestore(&_spinlock, level);
}
return mask;