Bluetooth: Consolidate bt_buf_get* functions

We may soon want to have a _wait() variant of bt_buf_get, so to avoid
the number of 'get' function growing too large consolidate the
existing get() and get_reserve() functions into a single one. The new
consolidated function also takes the type as input parameter so that
we know this from the very start and thereby plan for the split into
multiple buffer pools.

Change-Id: Ia09448565349def2be9bc08d9510fedd029480b4
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
Johan Hedberg 2015-04-28 11:19:26 +03:00 committed by Anas Nashif
commit d829fe9755
5 changed files with 20 additions and 26 deletions

View file

@ -142,19 +142,21 @@ void bt_uart_isr(void *unused)
return;
}
buf = bt_buf_get();
if (!buf) {
BT_ERR("Cannot get free buffer\n");
return;
}
switch (type) {
case H4_EVT:
buf->type = BT_EVT;
buf = bt_buf_get(BT_EVT, 0);
if (!buf) {
BT_ERR("No event buffers!\n");
return;
}
remaining = bt_uart_evt_recv(buf);
break;
case H4_ACL:
buf->type = BT_ACL_IN;
buf = bt_buf_get(BT_ACL_IN, 0);
if (!buf) {
BT_ERR("No ACL buffers!\n");
return;
}
remaining = bt_uart_acl_recv(buf);
break;
default:

View file

@ -65,11 +65,10 @@ struct bt_buf {
uint8_t buf[BT_BUF_MAX_DATA];
};
/* Get buffer from the available buffers pool */
struct bt_buf *bt_buf_get(void);
/* Same as bt_buf_get, but also reserve headroom for potential headers */
struct bt_buf *bt_buf_get_reserve(size_t reserve_head);
/* Get buffer from the available buffers pool with specified type and
* reserved headroom.
*/
struct bt_buf *bt_buf_get(enum bt_buf_type type, size_t reserve_head);
/* Place buffer back into the available buffers pool */
void bt_buf_put(struct bt_buf *buf);

View file

@ -45,7 +45,7 @@
static struct bt_buf buffers[NUM_BUFS];
static struct nano_fifo free_bufs;
struct bt_buf *bt_buf_get_reserve(size_t reserve_head)
struct bt_buf *bt_buf_get(enum bt_buf_type type, size_t reserve_head)
{
struct bt_buf *buf;
@ -55,6 +55,7 @@ struct bt_buf *bt_buf_get_reserve(size_t reserve_head)
return NULL;
}
buf->type = type;
buf->data = buf->buf + reserve_head;
buf->len = 0;
buf->sync = NULL;
@ -64,11 +65,6 @@ struct bt_buf *bt_buf_get_reserve(size_t reserve_head)
return buf;
}
struct bt_buf *bt_buf_get(void)
{
return bt_buf_get_reserve(0);
}
void bt_buf_put(struct bt_buf *buf)
{
BT_DBG("buf %p\n", buf);

View file

@ -267,8 +267,8 @@ void bt_conn_del(struct bt_conn *conn)
conn->state = BT_CONN_DISCONNECTED;
/* Send dummy buffers to wake up and kill the fibers */
nano_fifo_put(&conn->tx_queue, bt_buf_get());
nano_fifo_put(&conn->rx_queue, bt_buf_get());
nano_fifo_put(&conn->tx_queue, bt_buf_get(BT_ACL_OUT, 0));
nano_fifo_put(&conn->rx_queue, bt_buf_get(BT_ACL_IN, 0));
bt_conn_put(conn);
}
@ -314,12 +314,10 @@ struct bt_buf *bt_conn_create_pdu(struct bt_conn *conn, size_t len)
struct bt_hci_acl_hdr *hdr;
struct bt_buf *buf;
buf = bt_buf_get_reserve(dev->drv->head_reserve);
buf = bt_buf_get(BT_ACL_OUT, dev->drv->head_reserve);
if (!buf)
return NULL;
buf->type = BT_ACL_OUT;
hdr = (void *)bt_buf_add(buf, sizeof(*hdr));
hdr->handle = sys_cpu_to_le16(conn->handle);
hdr->len = len;

View file

@ -57,7 +57,7 @@ static struct bt_buf *bt_hci_cmd_create(uint16_t opcode, uint8_t param_len)
BT_DBG("opcode %x param_len %u\n", opcode, param_len);
buf = bt_buf_get_reserve(dev.drv->head_reserve);
buf = bt_buf_get(BT_CMD, dev.drv->head_reserve);
if (!buf) {
BT_ERR("Cannot get free buffer\n");
return NULL;
@ -65,7 +65,6 @@ static struct bt_buf *bt_hci_cmd_create(uint16_t opcode, uint8_t param_len)
BT_DBG("buf %p\n", buf);
buf->type = BT_CMD;
buf->opcode = opcode;
buf->sync = NULL;