summaryrefslogtreecommitdiff
path: root/nuttx/net/iob/iob_alloc.c
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-06-06 09:35:31 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-06-06 09:35:31 -0600
commit34c0b633c6530b8e7fce5479a5d0d41cd10b10cb (patch)
tree7ca3bf869409dd7665b31d5f7ff18fe42863c77b /nuttx/net/iob/iob_alloc.c
parentc7395ffbde4fb05be4f9f7dae07d2e3bb67c3438 (diff)
downloadnuttx-34c0b633c6530b8e7fce5479a5d0d41cd10b10cb.tar.gz
nuttx-34c0b633c6530b8e7fce5479a5d0d41cd10b10cb.tar.bz2
nuttx-34c0b633c6530b8e7fce5479a5d0d41cd10b10cb.zip
IOB: Add queue handling interfaces; improve lists
Diffstat (limited to 'nuttx/net/iob/iob_alloc.c')
-rw-r--r--nuttx/net/iob/iob_alloc.c36
1 files changed, 25 insertions, 11 deletions
diff --git a/nuttx/net/iob/iob_alloc.c b/nuttx/net/iob/iob_alloc.c
index a3c1bc64a..39c7d5f1c 100644
--- a/nuttx/net/iob/iob_alloc.c
+++ b/nuttx/net/iob/iob_alloc.c
@@ -39,8 +39,7 @@
#include <nuttx/config.h>
-#include <queue.h>
-
+#include <nuttx/arch.h>
#include <nuttx/net/iob.h>
#include "iob.h"
@@ -69,24 +68,39 @@
* Name: iob_alloc
*
* Description:
- * Allocate an I/O buffer by take the buffer at the head of the free list.
+ * Allocate an I/O buffer by taking the buffer at the head of the free list.
*
****************************************************************************/
FAR struct iob_s *iob_alloc(void)
{
FAR struct iob_s *iob;
+ irqstate_t flags;
+
+ /* We don't know what context we are called from so we use extreme measures
+ * to protect the free list: We disable interrupts very briefly.
+ */
- iob = (FAR struct iob_s *)sq_remfirst(&g_iob_freelist);
+ flags = irqsave();
+ iob = g_iob_freelist;
if (iob)
{
- iob->io_link.flink = NULL; /* Not in a chain */
- iob->io_flags = 0; /* Flags associated with the I/O buffer */
- iob->io_len = 0; /* Length of the data in the entry */
- iob->io_offset = 0; /* Offset to the beginning of data */
- iob->io_pktlen = 0; /* Total length of the packet */
- iob->io_priv = NULL; /* User private data attached to the I/O buffer */
+ /* Remove the I/O buffer from the free list */
+
+ g_iob_freelist = iob->io_flink;
+ irqrestore(flags);
+
+ /* Put the I/O buffer in a known state */
+
+ iob->io_flink = NULL; /* Not in a chain */
+ iob->io_flags = 0; /* Flags associated with the I/O buffer */
+ iob->io_len = 0; /* Length of the data in the entry */
+ iob->io_offset = 0; /* Offset to the beginning of data */
+ iob->io_pktlen = 0; /* Total length of the packet */
+ iob->io_priv = NULL; /* User private data attached to the I/O buffer */
+ return iob;
}
- return iob;
+ irqrestore(flags);
+ return NULL;
}