net: buf: Introduce net_buf_destroy() wrapper
This is only for use with custom destroy callbacks, so that the application gets isolated away from the details of how exactly the buffers are managed. This opens up the possibility of switching away from k_fifo to potentially better solutions, such as k_lifo. Change-Id: I0d8322fdec3500d8ae060ae471b9448aeaa4572a Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
parent
c8f8527d55
commit
45bc46d42e
5 changed files with 24 additions and 10 deletions
|
@ -469,8 +469,8 @@ struct net_buf_pool {
|
|||
* than an extern declaration.
|
||||
*
|
||||
* If provided with a custom destroy callback this callback is
|
||||
* responsible for eventually returning the buffer back to the free
|
||||
* buffers FIFO through k_fifo_put(buf->free, buf).
|
||||
* responsible for eventually calling net_buf_destroy() to complete the
|
||||
* process of returning the buffer to the pool.
|
||||
*
|
||||
* @param _name Name of the pool variable.
|
||||
* @param _count Number of buffers in the pool.
|
||||
|
@ -548,6 +548,20 @@ struct net_buf *net_buf_get_debug(struct k_fifo *fifo, int32_t timeout,
|
|||
struct net_buf *net_buf_get(struct k_fifo *fifo, int32_t timeout);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Destroy buffer from custom destroy callback
|
||||
*
|
||||
* This helper is only intended to be used from custom destroy callbacks.
|
||||
* If no custom destroy callback is given to NET_BUF_POOL_DEFINE() then
|
||||
* there is no need to use this API.
|
||||
*
|
||||
* @param buf Buffer to destroy.
|
||||
*/
|
||||
static inline void net_buf_destroy(struct net_buf *buf)
|
||||
{
|
||||
k_fifo_put(&buf->pool->free, buf);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initialize buffer with the given headroom.
|
||||
*
|
||||
|
|
|
@ -135,7 +135,7 @@ static void report_completed_packet(struct net_buf *buf)
|
|||
uint16_t handle = acl(buf)->handle;
|
||||
struct bt_hci_handle_count *hc;
|
||||
|
||||
k_fifo_put(&buf->pool->free, buf);
|
||||
net_buf_destroy(buf);
|
||||
|
||||
/* Do nothing if controller to host flow control is not supported */
|
||||
if (!(bt_dev.supported_commands[10] & 0x20)) {
|
||||
|
|
|
@ -198,7 +198,7 @@ void net_buf_unref(struct net_buf *buf)
|
|||
if (buf->pool->destroy) {
|
||||
buf->pool->destroy(buf);
|
||||
} else {
|
||||
k_fifo_put(&buf->pool->free, buf);
|
||||
net_buf_destroy(buf);
|
||||
}
|
||||
|
||||
buf = frags;
|
||||
|
|
|
@ -225,21 +225,21 @@ static inline void free_rx_bufs_func(struct net_buf *buf)
|
|||
{
|
||||
inc_free_rx_bufs_func(buf);
|
||||
|
||||
k_fifo_put(&buf->pool->free, buf);
|
||||
net_buf_destroy(buf);
|
||||
}
|
||||
|
||||
static inline void free_tx_bufs_func(struct net_buf *buf)
|
||||
{
|
||||
inc_free_tx_bufs_func(buf);
|
||||
|
||||
k_fifo_put(&buf->pool->free, buf);
|
||||
net_buf_destroy(buf);
|
||||
}
|
||||
|
||||
static inline void free_data_bufs_func(struct net_buf *buf)
|
||||
{
|
||||
inc_free_data_bufs_func(buf);
|
||||
|
||||
k_fifo_put(&buf->pool->free, buf);
|
||||
net_buf_destroy(buf);
|
||||
}
|
||||
|
||||
/* The RX and TX pools do not store any data. Only bearer / protocol
|
||||
|
|
|
@ -85,7 +85,7 @@ static void buf_destroy(struct net_buf *buf)
|
|||
|
||||
destroy_called++;
|
||||
assert_equal(pool, &bufs_pool, "Invalid free pointer in buffer");
|
||||
k_fifo_put(&pool->free, buf);
|
||||
net_buf_destroy(buf);
|
||||
}
|
||||
|
||||
static void frag_destroy(struct net_buf *buf)
|
||||
|
@ -95,7 +95,7 @@ static void frag_destroy(struct net_buf *buf)
|
|||
frag_destroy_called++;
|
||||
assert_equal(pool, &frags_pool,
|
||||
"Invalid free frag pointer in buffer");
|
||||
k_fifo_put(&pool->free, buf);
|
||||
net_buf_destroy(buf);
|
||||
}
|
||||
|
||||
static void frag_destroy_big(struct net_buf *buf)
|
||||
|
@ -105,7 +105,7 @@ static void frag_destroy_big(struct net_buf *buf)
|
|||
frag_destroy_called++;
|
||||
assert_equal(pool, &big_frags_pool,
|
||||
"Invalid free big frag pointer in buffer");
|
||||
k_fifo_put(&pool->free, buf);
|
||||
net_buf_destroy(buf);
|
||||
}
|
||||
|
||||
static const char example_data[] = "0123456789"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue