From aa3e778dc6374b6dc3005eec5f207c4b4eafa6e3 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 14 Feb 2016 08:38:44 -0600 Subject: [PATCH] nuttx/net: Replace irqsave() with enter_critical_section(); replace irqrestore() with leave_critical_section() --- net/arp/arp_notify.c | 14 +++++++------- net/icmpv6/icmpv6_notify.c | 14 +++++++------- net/icmpv6/icmpv6_rnotify.c | 14 +++++++------- net/iob/iob_alloc.c | 11 ++++++----- net/iob/iob_alloc_qentry.c | 9 +++++---- net/iob/iob_free.c | 23 ++++------------------- net/iob/iob_free_qentry.c | 7 ++++--- net/utils/net_lock.c | 7 ++++--- 8 files changed, 44 insertions(+), 55 deletions(-) diff --git a/net/arp/arp_notify.c b/net/arp/arp_notify.c index e5a1559502b..0966c92292e 100644 --- a/net/arp/arp_notify.c +++ b/net/arp/arp_notify.c @@ -48,7 +48,7 @@ #include #include -#include +#include #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 */ - flags = irqsave(); + flags = enter_critical_section(); notify->nt_flink = g_arp_waiters; 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). */ - flags = irqsave(); + flags = enter_critical_section(); for (prev = NULL, curr = g_arp_waiters; curr && curr != notify; prev = curr, curr = curr->nt_flink); @@ -154,7 +154,7 @@ int arp_wait_cancel(FAR struct arp_notify_s *notify) ret = OK; } - irqrestore(flags); + leave_critical_section(flags); (void)sem_destroy(¬ify->nt_sem); return ret; } @@ -184,7 +184,7 @@ int arp_wait(FAR struct arp_notify_s *notify, FAR struct timespec *timeout) * enabled while we wait. */ - flags = irqsave(); + flags = enter_critical_section(); DEBUGVERIFY(clock_gettime(CLOCK_REALTIME, &abstime)); 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 */ - irqrestore(flags); + leave_critical_section(flags); return ret; } diff --git a/net/icmpv6/icmpv6_notify.c b/net/icmpv6/icmpv6_notify.c index 07191a53425..4185b5a3525 100644 --- a/net/icmpv6/icmpv6_notify.c +++ b/net/icmpv6/icmpv6_notify.c @@ -48,7 +48,7 @@ #include #include -#include +#include #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 */ - flags = irqsave(); + flags = enter_critical_section(); notify->nt_flink = g_icmpv6_waiters; 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). */ - flags = irqsave(); + flags = enter_critical_section(); for (prev = NULL, curr = g_icmpv6_waiters; curr && curr != notify; prev = curr, curr = curr->nt_flink); @@ -156,7 +156,7 @@ int icmpv6_wait_cancel(FAR struct icmpv6_notify_s *notify) ret = OK; } - irqrestore(flags); + leave_critical_section(flags); (void)sem_destroy(¬ify->nt_sem); return ret; } @@ -186,7 +186,7 @@ int icmpv6_wait(FAR struct icmpv6_notify_s *notify, * be re-enabled while we wait. */ - flags = irqsave(); + flags = enter_critical_section(); DEBUGVERIFY(clock_gettime(CLOCK_REALTIME, &abstime)); 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 */ - irqrestore(flags); + leave_critical_section(flags); return ret; } diff --git a/net/icmpv6/icmpv6_rnotify.c b/net/icmpv6/icmpv6_rnotify.c index d7c04976eb7..c8e38e3d633 100644 --- a/net/icmpv6/icmpv6_rnotify.c +++ b/net/icmpv6/icmpv6_rnotify.c @@ -49,7 +49,7 @@ #include #include -#include +#include #include "netdev/netdev.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 */ - flags = irqsave(); + flags = enter_critical_section(); notify->rn_flink = g_icmpv6_rwaiters; g_icmpv6_rwaiters = notify; - irqrestore(flags); + leave_critical_section(flags); #else /* 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). */ - flags = irqsave(); + flags = enter_critical_section(); for (prev = NULL, curr = g_icmpv6_rwaiters; curr && curr != notify; prev = curr, curr = curr->rn_flink); @@ -238,7 +238,7 @@ int icmpv6_rwait_cancel(FAR struct icmpv6_rnotify_s *notify) ret = OK; } - irqrestore(flags); + leave_critical_section(flags); (void)sem_destroy(¬ify->rn_sem); return ret; @@ -282,7 +282,7 @@ int icmpv6_rwait(FAR struct icmpv6_rnotify_s *notify, * be re-enabled while we wait. */ - flags = irqsave(); + flags = enter_critical_section(); DEBUGVERIFY(clock_gettime(CLOCK_REALTIME, &abstime)); 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 */ - irqrestore(flags); + leave_critical_section(flags); return ret; } diff --git a/net/iob/iob_alloc.c b/net/iob/iob_alloc.c index 2583fc41363..e5483a2c3e6 100644 --- a/net/iob/iob_alloc.c +++ b/net/iob/iob_alloc.c @@ -50,6 +50,7 @@ #include #include +#include #include #include @@ -89,7 +90,7 @@ static FAR struct iob_s *iob_allocwait(bool throttled) * we are waiting for I/O buffers to become free. */ - flags = irqsave(); + flags = enter_critical_section(); do { /* 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); - irqrestore(flags); + leave_critical_section(flags); return iob; } @@ -219,7 +220,7 @@ FAR struct iob_s *iob_tryalloc(bool throttled) * to protect the free list: We disable interrupts very briefly. */ - flags = irqsave(); + flags = enter_critical_section(); #if CONFIG_IOB_THROTTLE > 0 /* 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--; DEBUGASSERT(g_throttle_sem.semcount >= -CONFIG_IOB_THROTTLE); #endif - irqrestore(flags); + leave_critical_section(flags); /* 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; } diff --git a/net/iob/iob_alloc_qentry.c b/net/iob/iob_alloc_qentry.c index 2aab1e6353b..c1a9f54a973 100644 --- a/net/iob/iob_alloc_qentry.c +++ b/net/iob/iob_alloc_qentry.c @@ -50,6 +50,7 @@ #include #include +#include #include #include @@ -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. */ - flags = irqsave(); + flags = enter_critical_section(); do { /* 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); - irqrestore(flags); + leave_critical_section(flags); 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. */ - flags = irqsave(); + flags = enter_critical_section(); iobq = g_iob_freeqlist; if (iobq) { @@ -233,7 +234,7 @@ FAR struct iob_qentry_s *iob_tryalloc_qentry(void) iobq->qe_head = NULL; /* Nothing is contained */ } - irqrestore(flags); + leave_critical_section(flags); return iobq; } diff --git a/net/iob/iob_free.c b/net/iob/iob_free.c index 984287600d9..53d8f6fb1de 100644 --- a/net/iob/iob_free.c +++ b/net/iob/iob_free.c @@ -1,7 +1,7 @@ /**************************************************************************** * 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 * * Redistribution and use in source and binary forms, with or without @@ -50,27 +50,12 @@ #include #include +#include #include #include #include "iob.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - /**************************************************************************** * 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. */ - flags = irqsave(); + flags = enter_critical_section(); iob->io_flink = g_iob_freelist; g_iob_freelist = iob; @@ -138,7 +123,7 @@ FAR struct iob_s *iob_free(FAR struct iob_s *iob) #if CONFIG_IOB_THROTTLE > 0 sem_post(&g_throttle_sem); #endif - irqrestore(flags); + leave_critical_section(flags); /* And return the I/O buffer after the one that was freed */ diff --git a/net/iob/iob_free_qentry.c b/net/iob/iob_free_qentry.c index f93f16f8f63..2c5e6fc6e94 100644 --- a/net/iob/iob_free_qentry.c +++ b/net/iob/iob_free_qentry.c @@ -1,7 +1,7 @@ /**************************************************************************** * 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 * * Redistribution and use in source and binary forms, with or without @@ -49,6 +49,7 @@ #include #include +#include #include #include @@ -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. */ - flags = irqsave(); + flags = enter_critical_section(); iobq->qe_flink = g_iob_freeqlist; g_iob_freeqlist = iobq; /* Signal that an I/O buffer chain container is available */ 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 */ diff --git a/net/utils/net_lock.c b/net/utils/net_lock.c index da359840ceb..49ce834070f 100644 --- a/net/utils/net_lock.c +++ b/net/utils/net_lock.c @@ -1,7 +1,7 @@ /**************************************************************************** * 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 * * Redistribution and use in source and binary forms, with or without @@ -45,6 +45,7 @@ #include #include +#include #include #include @@ -197,7 +198,7 @@ int net_timedwait(sem_t *sem, FAR const struct timespec *abstime) irqstate_t flags; int ret; - flags = irqsave(); /* No interrupts */ + flags = enter_critical_section(); /* No interrupts */ sched_lock(); /* No context switches */ if (g_holder == me) { @@ -235,7 +236,7 @@ int net_timedwait(sem_t *sem, FAR const struct timespec *abstime) } sched_unlock(); - irqrestore(flags); + leave_critical_section(flags); return ret; }