From 3b81e58047cfc76ce9f8c72aebfca22080049873 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 28 Jun 2014 11:35:14 -0600 Subject: [PATCH] NET: Fix some errors in recent network I/O buffering when stack runs from interrupt level --- include/nuttx/net/net.h | 2 +- net/iob/iob_alloc.c | 16 ++++++++++++---- sched/os_start.c | 7 +------ sched/sem_trywait.c | 4 ++-- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/include/nuttx/net/net.h b/include/nuttx/net/net.h index 707a499b004..fb7ff913663 100644 --- a/include/nuttx/net/net.h +++ b/include/nuttx/net/net.h @@ -156,7 +156,7 @@ int net_checksd(int fd, int oflags); * under sched/ */ -void weak_function net_initialize(void); +void net_initialize(void); void net_initlist(FAR struct socketlist *list); void net_releaselist(FAR struct socketlist *list); diff --git a/net/iob/iob_alloc.c b/net/iob/iob_alloc.c index 179908d4693..1bfbab7c41d 100644 --- a/net/iob/iob_alloc.c +++ b/net/iob/iob_alloc.c @@ -107,8 +107,7 @@ static FAR struct iob_s *iob_tryalloc(bool throttled) #if CONFIG_IOB_THROTTLE > 0 /* If there are free I/O buffers for this allocation */ - DEBUGVERIFY(sem_getvalue(sem, &semcount)); - if (semcount > 0) + if (sem->semcount > 0) #endif { /* Take the I/O buffer from the head of the free list */ @@ -122,9 +121,18 @@ static FAR struct iob_s *iob_tryalloc(bool throttled) */ g_iob_freelist = iob->io_flink; - DEBUGVERIFY(sem_trywait(&g_iob_sem)); + + /* Take a semaphore count. Note that we cannot do this in + * in the orthodox way by calling sem_wait() or sem_trywait() + * because this function may be called from an interrupt + * handler. Fortunately we know at at least one free buffer + * so a simple decrement is all that is needed. + */ + + g_iob_sem.semcount--; + DEBUGASSERT(g_iob_sem.semcount >= 0); + #if CONFIG_IOB_THROTTLE > 0 - //DEBUGVERIFY(sem_trywait(&g_throttle_sem)); g_throttle_sem.semcount--; DEBUGASSERT(g_throttle_sem.semcount >= -CONFIG_IOB_THROTTLE); #endif diff --git a/sched/os_start.c b/sched/os_start.c index a7cd4b9f4ff..194b42ab2ba 100644 --- a/sched/os_start.c +++ b/sched/os_start.c @@ -448,12 +448,7 @@ void os_start(void) /* Initialize the network system */ #ifdef CONFIG_NET -#if 0 - if (net_initialize != NULL) -#endif - { - net_initialize(); - } + net_initialize(); #endif /* The processor specific details of running the operating system diff --git a/sched/sem_trywait.c b/sched/sem_trywait.c index ce3e80b3ac5..38de330a519 100644 --- a/sched/sem_trywait.c +++ b/sched/sem_trywait.c @@ -116,8 +116,8 @@ int sem_trywait(FAR sem_t *sem) saved_state = irqsave(); - /* Any further errors could only be occurred because the semaphore - * is not available. + /* Any further errors could only occurr because the semaphore is not + * available. */ set_errno(EAGAIN);