Bluetooth: conn: Add bt_conn_create_pdu_timeout

This adds bt_conn_create_pdu_timeout function which can be used
to provide a timeout when allocating a buffer.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This commit is contained in:
Luiz Augusto von Dentz 2019-08-27 14:23:54 +03:00 committed by Carles Cufí
commit 1af31671e3
4 changed files with 27 additions and 10 deletions

View file

@ -2312,7 +2312,8 @@ int bt_conn_le_conn_update(struct bt_conn *conn,
return bt_hci_cmd_send(BT_HCI_OP_LE_CONN_UPDATE, buf);
}
struct net_buf *bt_conn_create_pdu(struct net_buf_pool *pool, size_t reserve)
struct net_buf *bt_conn_create_pdu_timeout(struct net_buf_pool *pool,
size_t reserve, s32_t timeout)
{
struct net_buf *buf;
@ -2327,24 +2328,29 @@ struct net_buf *bt_conn_create_pdu(struct net_buf_pool *pool, size_t reserve)
}
if (IS_ENABLED(CONFIG_BT_DEBUG_CONN) ||
k_current_get() == &k_sys_work_q.thread) {
(k_current_get() == &k_sys_work_q.thread && timeout == K_FOREVER)) {
buf = net_buf_alloc(pool, K_NO_WAIT);
if (!buf) {
BT_WARN("Unable to allocate buffer");
BT_WARN("Unable to allocate buffer with K_NO_WAIT");
/* Cannot block with K_FOREVER on k_sys_work_q as that
* can cause a deadlock when trying to dispatch TX
* notification.
*/
if (k_current_get() == &k_sys_work_q.thread) {
BT_WARN("Unable to allocate buffer: timeout %d",
timeout);
return NULL;
}
buf = net_buf_alloc(pool, K_FOREVER);
buf = net_buf_alloc(pool, timeout);
}
} else {
buf = net_buf_alloc(pool, K_FOREVER);
buf = net_buf_alloc(pool, timeout);
}
__ASSERT_NO_MSG(buf);
if (!buf) {
BT_WARN("Unable to allocate buffer: timeout %d", timeout);
return NULL;
}
reserve += sizeof(struct bt_hci_acl_hdr) + CONFIG_BT_HCI_RESERVE;
net_buf_reserve(buf, reserve);