mirror of
https://github.com/apache/nuttx.git
synced 2025-01-12 22:08:35 +08:00
net/bufpool: Use SEM_INITIALIZER
to init sem
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
This commit is contained in:
parent
407a62a33a
commit
f702f1705f
2 changed files with 9 additions and 24 deletions
|
@ -61,18 +61,6 @@ struct net_bufnode_s
|
|||
void net_bufpool_init(FAR struct net_bufpool_s *pool)
|
||||
{
|
||||
int i;
|
||||
unsigned int maxalloc;
|
||||
|
||||
if (pool->dynalloc > 0)
|
||||
{
|
||||
maxalloc = pool->u.maxalloc > 0 ? pool->u.maxalloc : INT16_MAX;
|
||||
}
|
||||
else
|
||||
{
|
||||
maxalloc = pool->prealloc;
|
||||
}
|
||||
|
||||
nxsem_init(&pool->u.sem, 0, maxalloc);
|
||||
|
||||
sq_init(&pool->freebuffers);
|
||||
for (i = 0; i < pool->prealloc; i++)
|
||||
|
@ -107,7 +95,7 @@ FAR void *net_bufpool_timedalloc(FAR struct net_bufpool_s *pool,
|
|||
int ret;
|
||||
int i;
|
||||
|
||||
ret = net_sem_timedwait_uninterruptible(&pool->u.sem, timeout);
|
||||
ret = net_sem_timedwait_uninterruptible(&pool->sem, timeout);
|
||||
if (ret != OK)
|
||||
{
|
||||
return NULL;
|
||||
|
@ -168,7 +156,7 @@ void net_bufpool_free(FAR struct net_bufpool_s *pool, FAR void *node)
|
|||
sq_addlast(&net_bufnode->node, &pool->freebuffers);
|
||||
}
|
||||
|
||||
nxsem_post(&pool->u.sem);
|
||||
nxsem_post(&pool->sem);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -187,7 +175,7 @@ int net_bufpool_test(FAR struct net_bufpool_s *pool)
|
|||
int val = 0;
|
||||
int ret;
|
||||
|
||||
ret = nxsem_get_value(&pool->u.sem, &val);
|
||||
ret = nxsem_get_value(&pool->sem, &val);
|
||||
if (ret >= 0)
|
||||
{
|
||||
ret = val > 0 ? OK : -ENOSPC;
|
||||
|
|
|
@ -84,7 +84,10 @@
|
|||
* maxalloc: The number of max allocations, 0 means no limit
|
||||
*/
|
||||
|
||||
#define NET_BUFPOOL_DECLARE(pool,nodesize,prealloc,dynalloc,maxalloc) \
|
||||
#define NET_BUFPOOL_MAX(prealloc, dynalloc, maxalloc) \
|
||||
(dynalloc) <= 0 ? (prealloc) : ((maxalloc) > 0 ? (maxalloc) : INT16_MAX)
|
||||
|
||||
#define NET_BUFPOOL_DECLARE(pool, nodesize, prealloc, dynalloc, maxalloc) \
|
||||
static char pool##_buffer[prealloc][nodesize]; \
|
||||
static struct net_bufpool_s pool = \
|
||||
{ \
|
||||
|
@ -92,9 +95,7 @@
|
|||
prealloc, \
|
||||
dynalloc, \
|
||||
nodesize, \
|
||||
{ \
|
||||
maxalloc \
|
||||
} \
|
||||
SEM_INITIALIZER(NET_BUFPOOL_MAX(prealloc, dynalloc, maxalloc)) \
|
||||
};
|
||||
|
||||
#define NET_BUFPOOL_INIT(p) net_bufpool_init(&p)
|
||||
|
@ -128,11 +129,7 @@ struct net_bufpool_s
|
|||
const int dynalloc; /* The number per dynamic allocations */
|
||||
const int nodesize; /* The size of each node in the pool */
|
||||
|
||||
union
|
||||
{
|
||||
int16_t maxalloc; /* The number of max allocations, used before init */
|
||||
sem_t sem; /* The semaphore for waiting for free buffers */
|
||||
} u;
|
||||
sem_t sem; /* The semaphore for waiting for free buffers */
|
||||
|
||||
sq_queue_t freebuffers;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue