mirror of
https://github.com/apache/nuttx.git
synced 2026-05-28 11:56:10 +08:00
nuttx/net: Replace irqsave() with enter_critical_section(); replace irqrestore() with leave_critical_section()
This commit is contained in:
@@ -48,7 +48,7 @@
|
|||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
|
|
||||||
#include <nuttx/net/net.h>
|
#include <nuttx/net/net.h>
|
||||||
#include <arch/irq.h>
|
#include <nuttx/irq.h>
|
||||||
|
|
||||||
#include "arp/arp.h"
|
#include "arp/arp.h"
|
||||||
|
|
||||||
@@ -104,10 +104,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 */
|
/* Add the wait structure to the list with interrupts disabled */
|
||||||
|
|
||||||
flags = irqsave();
|
flags = enter_critical_section();
|
||||||
notify->nt_flink = g_arp_waiters;
|
notify->nt_flink = g_arp_waiters;
|
||||||
g_arp_waiters = notify;
|
g_arp_waiters = notify;
|
||||||
irqrestore(flags);
|
leave_critical_section(flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -134,7 +134,7 @@ int arp_wait_cancel(FAR struct arp_notify_s *notify)
|
|||||||
* head of the list).
|
* head of the list).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
flags = irqsave();
|
flags = enter_critical_section();
|
||||||
for (prev = NULL, curr = g_arp_waiters;
|
for (prev = NULL, curr = g_arp_waiters;
|
||||||
curr && curr != notify;
|
curr && curr != notify;
|
||||||
prev = curr, curr = curr->nt_flink);
|
prev = curr, curr = curr->nt_flink);
|
||||||
@@ -154,7 +154,7 @@ int arp_wait_cancel(FAR struct arp_notify_s *notify)
|
|||||||
ret = OK;
|
ret = OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
irqrestore(flags);
|
leave_critical_section(flags);
|
||||||
(void)sem_destroy(¬ify->nt_sem);
|
(void)sem_destroy(¬ify->nt_sem);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -184,7 +184,7 @@ int arp_wait(FAR struct arp_notify_s *notify, FAR struct timespec *timeout)
|
|||||||
* enabled while we wait.
|
* enabled while we wait.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
flags = irqsave();
|
flags = enter_critical_section();
|
||||||
DEBUGVERIFY(clock_gettime(CLOCK_REALTIME, &abstime));
|
DEBUGVERIFY(clock_gettime(CLOCK_REALTIME, &abstime));
|
||||||
|
|
||||||
abstime.tv_sec += timeout->tv_sec;
|
abstime.tv_sec += timeout->tv_sec;
|
||||||
@@ -220,7 +220,7 @@ int arp_wait(FAR struct arp_notify_s *notify, FAR struct timespec *timeout)
|
|||||||
|
|
||||||
/* Re-enable interrupts and return the result of the wait */
|
/* Re-enable interrupts and return the result of the wait */
|
||||||
|
|
||||||
irqrestore(flags);
|
leave_critical_section(flags);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,7 +48,7 @@
|
|||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
|
|
||||||
#include <nuttx/net/net.h>
|
#include <nuttx/net/net.h>
|
||||||
#include <arch/irq.h>
|
#include <nuttx/irq.h>
|
||||||
|
|
||||||
#include "icmpv6/icmpv6.h"
|
#include "icmpv6/icmpv6.h"
|
||||||
|
|
||||||
@@ -105,10 +105,10 @@ void icmpv6_wait_setup(const net_ipv6addr_t ipaddr,
|
|||||||
|
|
||||||
/* Add the wait structure to the list with interrupts disabled */
|
/* Add the wait structure to the list with interrupts disabled */
|
||||||
|
|
||||||
flags = irqsave();
|
flags = enter_critical_section();
|
||||||
notify->nt_flink = g_icmpv6_waiters;
|
notify->nt_flink = g_icmpv6_waiters;
|
||||||
g_icmpv6_waiters = notify;
|
g_icmpv6_waiters = notify;
|
||||||
irqrestore(flags);
|
leave_critical_section(flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -136,7 +136,7 @@ int icmpv6_wait_cancel(FAR struct icmpv6_notify_s *notify)
|
|||||||
* head of the list).
|
* head of the list).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
flags = irqsave();
|
flags = enter_critical_section();
|
||||||
for (prev = NULL, curr = g_icmpv6_waiters;
|
for (prev = NULL, curr = g_icmpv6_waiters;
|
||||||
curr && curr != notify;
|
curr && curr != notify;
|
||||||
prev = curr, curr = curr->nt_flink);
|
prev = curr, curr = curr->nt_flink);
|
||||||
@@ -156,7 +156,7 @@ int icmpv6_wait_cancel(FAR struct icmpv6_notify_s *notify)
|
|||||||
ret = OK;
|
ret = OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
irqrestore(flags);
|
leave_critical_section(flags);
|
||||||
(void)sem_destroy(¬ify->nt_sem);
|
(void)sem_destroy(¬ify->nt_sem);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -186,7 +186,7 @@ int icmpv6_wait(FAR struct icmpv6_notify_s *notify,
|
|||||||
* be re-enabled while we wait.
|
* be re-enabled while we wait.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
flags = irqsave();
|
flags = enter_critical_section();
|
||||||
DEBUGVERIFY(clock_gettime(CLOCK_REALTIME, &abstime));
|
DEBUGVERIFY(clock_gettime(CLOCK_REALTIME, &abstime));
|
||||||
|
|
||||||
abstime.tv_sec += timeout->tv_sec;
|
abstime.tv_sec += timeout->tv_sec;
|
||||||
@@ -212,7 +212,7 @@ int icmpv6_wait(FAR struct icmpv6_notify_s *notify,
|
|||||||
|
|
||||||
/* Re-enable interrupts and return the result of the wait */
|
/* Re-enable interrupts and return the result of the wait */
|
||||||
|
|
||||||
irqrestore(flags);
|
leave_critical_section(flags);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,7 @@
|
|||||||
|
|
||||||
#include <nuttx/net/net.h>
|
#include <nuttx/net/net.h>
|
||||||
#include <nuttx/net/netdev.h>
|
#include <nuttx/net/netdev.h>
|
||||||
#include <arch/irq.h>
|
#include <nuttx/irq.h>
|
||||||
|
|
||||||
#include "netdev/netdev.h"
|
#include "netdev/netdev.h"
|
||||||
#include "utils/utils.h"
|
#include "utils/utils.h"
|
||||||
@@ -170,10 +170,10 @@ void icmpv6_rwait_setup(FAR struct net_driver_s *dev,
|
|||||||
|
|
||||||
/* Add the wait structure to the list with interrupts disabled */
|
/* Add the wait structure to the list with interrupts disabled */
|
||||||
|
|
||||||
flags = irqsave();
|
flags = enter_critical_section();
|
||||||
notify->rn_flink = g_icmpv6_rwaiters;
|
notify->rn_flink = g_icmpv6_rwaiters;
|
||||||
g_icmpv6_rwaiters = notify;
|
g_icmpv6_rwaiters = notify;
|
||||||
irqrestore(flags);
|
leave_critical_section(flags);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
/* If there is only a single network device, then there can be only a
|
/* If there is only a single network device, then there can be only a
|
||||||
@@ -218,7 +218,7 @@ int icmpv6_rwait_cancel(FAR struct icmpv6_rnotify_s *notify)
|
|||||||
* head of the list).
|
* head of the list).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
flags = irqsave();
|
flags = enter_critical_section();
|
||||||
for (prev = NULL, curr = g_icmpv6_rwaiters;
|
for (prev = NULL, curr = g_icmpv6_rwaiters;
|
||||||
curr && curr != notify;
|
curr && curr != notify;
|
||||||
prev = curr, curr = curr->rn_flink);
|
prev = curr, curr = curr->rn_flink);
|
||||||
@@ -238,7 +238,7 @@ int icmpv6_rwait_cancel(FAR struct icmpv6_rnotify_s *notify)
|
|||||||
ret = OK;
|
ret = OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
irqrestore(flags);
|
leave_critical_section(flags);
|
||||||
(void)sem_destroy(¬ify->rn_sem);
|
(void)sem_destroy(¬ify->rn_sem);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
@@ -282,7 +282,7 @@ int icmpv6_rwait(FAR struct icmpv6_rnotify_s *notify,
|
|||||||
* be re-enabled while we wait.
|
* be re-enabled while we wait.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
flags = irqsave();
|
flags = enter_critical_section();
|
||||||
DEBUGVERIFY(clock_gettime(CLOCK_REALTIME, &abstime));
|
DEBUGVERIFY(clock_gettime(CLOCK_REALTIME, &abstime));
|
||||||
|
|
||||||
abstime.tv_sec += timeout->tv_sec;
|
abstime.tv_sec += timeout->tv_sec;
|
||||||
@@ -308,7 +308,7 @@ int icmpv6_rwait(FAR struct icmpv6_rnotify_s *notify,
|
|||||||
|
|
||||||
/* Re-enable interrupts and return the result of the wait */
|
/* Re-enable interrupts and return the result of the wait */
|
||||||
|
|
||||||
irqrestore(flags);
|
leave_critical_section(flags);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
-5
@@ -50,6 +50,7 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <nuttx/irq.h>
|
||||||
#include <nuttx/arch.h>
|
#include <nuttx/arch.h>
|
||||||
#include <nuttx/net/iob.h>
|
#include <nuttx/net/iob.h>
|
||||||
|
|
||||||
@@ -89,7 +90,7 @@ static FAR struct iob_s *iob_allocwait(bool throttled)
|
|||||||
* we are waiting for I/O buffers to become free.
|
* we are waiting for I/O buffers to become free.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
flags = irqsave();
|
flags = enter_critical_section();
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
/* Try to get an I/O buffer. If successful, the semaphore count
|
/* Try to get an I/O buffer. If successful, the semaphore count
|
||||||
@@ -158,7 +159,7 @@ static FAR struct iob_s *iob_allocwait(bool throttled)
|
|||||||
}
|
}
|
||||||
while (ret == OK && iob == NULL);
|
while (ret == OK && iob == NULL);
|
||||||
|
|
||||||
irqrestore(flags);
|
leave_critical_section(flags);
|
||||||
return iob;
|
return iob;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,7 +220,7 @@ FAR struct iob_s *iob_tryalloc(bool throttled)
|
|||||||
* to protect the free list: We disable interrupts very briefly.
|
* to protect the free list: We disable interrupts very briefly.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
flags = irqsave();
|
flags = enter_critical_section();
|
||||||
|
|
||||||
#if CONFIG_IOB_THROTTLE > 0
|
#if CONFIG_IOB_THROTTLE > 0
|
||||||
/* If there are free I/O buffers for this allocation */
|
/* If there are free I/O buffers for this allocation */
|
||||||
@@ -257,7 +258,7 @@ FAR struct iob_s *iob_tryalloc(bool throttled)
|
|||||||
g_throttle_sem.semcount--;
|
g_throttle_sem.semcount--;
|
||||||
DEBUGASSERT(g_throttle_sem.semcount >= -CONFIG_IOB_THROTTLE);
|
DEBUGASSERT(g_throttle_sem.semcount >= -CONFIG_IOB_THROTTLE);
|
||||||
#endif
|
#endif
|
||||||
irqrestore(flags);
|
leave_critical_section(flags);
|
||||||
|
|
||||||
/* Put the I/O buffer in a known state */
|
/* Put the I/O buffer in a known state */
|
||||||
|
|
||||||
@@ -269,6 +270,6 @@ FAR struct iob_s *iob_tryalloc(bool throttled)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
irqrestore(flags);
|
leave_critical_section(flags);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,6 +50,7 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <nuttx/irq.h>
|
||||||
#include <nuttx/arch.h>
|
#include <nuttx/arch.h>
|
||||||
#include <nuttx/net/iob.h>
|
#include <nuttx/net/iob.h>
|
||||||
|
|
||||||
@@ -83,7 +84,7 @@ static FAR struct iob_qentry_s *iob_allocwait_qentry(void)
|
|||||||
* re-enabled while we are waiting for I/O buffers to become free.
|
* re-enabled while we are waiting for I/O buffers to become free.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
flags = irqsave();
|
flags = enter_critical_section();
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
/* Try to get an I/O buffer chain container. If successful, the
|
/* Try to get an I/O buffer chain container. If successful, the
|
||||||
@@ -152,7 +153,7 @@ static FAR struct iob_qentry_s *iob_allocwait_qentry(void)
|
|||||||
}
|
}
|
||||||
while (ret == OK && !qentry);
|
while (ret == OK && !qentry);
|
||||||
|
|
||||||
irqrestore(flags);
|
leave_critical_section(flags);
|
||||||
return qentry;
|
return qentry;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,7 +208,7 @@ FAR struct iob_qentry_s *iob_tryalloc_qentry(void)
|
|||||||
* to protect the free list: We disable interrupts very briefly.
|
* to protect the free list: We disable interrupts very briefly.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
flags = irqsave();
|
flags = enter_critical_section();
|
||||||
iobq = g_iob_freeqlist;
|
iobq = g_iob_freeqlist;
|
||||||
if (iobq)
|
if (iobq)
|
||||||
{
|
{
|
||||||
@@ -233,7 +234,7 @@ FAR struct iob_qentry_s *iob_tryalloc_qentry(void)
|
|||||||
iobq->qe_head = NULL; /* Nothing is contained */
|
iobq->qe_head = NULL; /* Nothing is contained */
|
||||||
}
|
}
|
||||||
|
|
||||||
irqrestore(flags);
|
leave_critical_section(flags);
|
||||||
return iobq;
|
return iobq;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-19
@@ -1,7 +1,7 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* net/iob/iob_free.c
|
* net/iob/iob_free.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2014, 2016 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -50,27 +50,12 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
|
|
||||||
|
#include <nuttx/irq.h>
|
||||||
#include <nuttx/arch.h>
|
#include <nuttx/arch.h>
|
||||||
#include <nuttx/net/iob.h>
|
#include <nuttx/net/iob.h>
|
||||||
|
|
||||||
#include "iob.h"
|
#include "iob.h"
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Pre-processor Definitions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Types
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Data
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Data
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@@ -128,7 +113,7 @@ FAR struct iob_s *iob_free(FAR struct iob_s *iob)
|
|||||||
* protect the free list: We disable interrupts very briefly.
|
* protect the free list: We disable interrupts very briefly.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
flags = irqsave();
|
flags = enter_critical_section();
|
||||||
iob->io_flink = g_iob_freelist;
|
iob->io_flink = g_iob_freelist;
|
||||||
g_iob_freelist = iob;
|
g_iob_freelist = iob;
|
||||||
|
|
||||||
@@ -138,7 +123,7 @@ FAR struct iob_s *iob_free(FAR struct iob_s *iob)
|
|||||||
#if CONFIG_IOB_THROTTLE > 0
|
#if CONFIG_IOB_THROTTLE > 0
|
||||||
sem_post(&g_throttle_sem);
|
sem_post(&g_throttle_sem);
|
||||||
#endif
|
#endif
|
||||||
irqrestore(flags);
|
leave_critical_section(flags);
|
||||||
|
|
||||||
/* And return the I/O buffer after the one that was freed */
|
/* And return the I/O buffer after the one that was freed */
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* net/iob/iob_free_qentry.c
|
* net/iob/iob_free_qentry.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2014, 2016 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -49,6 +49,7 @@
|
|||||||
#include <semaphore.h>
|
#include <semaphore.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
|
#include <nuttx/irq.h>
|
||||||
#include <nuttx/arch.h>
|
#include <nuttx/arch.h>
|
||||||
#include <nuttx/net/iob.h>
|
#include <nuttx/net/iob.h>
|
||||||
|
|
||||||
@@ -95,14 +96,14 @@ FAR struct iob_qentry_s *iob_free_qentry(FAR struct iob_qentry_s *iobq)
|
|||||||
* measures to protect the free list: We disable interrupts very briefly.
|
* measures to protect the free list: We disable interrupts very briefly.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
flags = irqsave();
|
flags = enter_critical_section();
|
||||||
iobq->qe_flink = g_iob_freeqlist;
|
iobq->qe_flink = g_iob_freeqlist;
|
||||||
g_iob_freeqlist = iobq;
|
g_iob_freeqlist = iobq;
|
||||||
|
|
||||||
/* Signal that an I/O buffer chain container is available */
|
/* Signal that an I/O buffer chain container is available */
|
||||||
|
|
||||||
sem_post(&g_qentry_sem);
|
sem_post(&g_qentry_sem);
|
||||||
irqrestore(flags);
|
leave_critical_section(flags);
|
||||||
|
|
||||||
/* And return the I/O buffer chain container after the one that was freed */
|
/* And return the I/O buffer chain container after the one that was freed */
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* net/utils/net_lock.c
|
* net/utils/net_lock.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2011-2012, 2014-2015 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2011-2012, 2014-2016 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -45,6 +45,7 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
|
|
||||||
|
#include <nuttx/irq.h>
|
||||||
#include <nuttx/arch.h>
|
#include <nuttx/arch.h>
|
||||||
#include <nuttx/net/net.h>
|
#include <nuttx/net/net.h>
|
||||||
|
|
||||||
@@ -197,7 +198,7 @@ int net_timedwait(sem_t *sem, FAR const struct timespec *abstime)
|
|||||||
irqstate_t flags;
|
irqstate_t flags;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
flags = irqsave(); /* No interrupts */
|
flags = enter_critical_section(); /* No interrupts */
|
||||||
sched_lock(); /* No context switches */
|
sched_lock(); /* No context switches */
|
||||||
if (g_holder == me)
|
if (g_holder == me)
|
||||||
{
|
{
|
||||||
@@ -235,7 +236,7 @@ int net_timedwait(sem_t *sem, FAR const struct timespec *abstime)
|
|||||||
}
|
}
|
||||||
|
|
||||||
sched_unlock();
|
sched_unlock();
|
||||||
irqrestore(flags);
|
leave_critical_section(flags);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user