Bluetooth: Add reference counting for buffers

In certain scenarios we want to keep the buffers around for longer
and avoid the default bt_buf_put() calls from putting them back to the
available buffers queue. This patch adds reference counting for the
buffers, along with a bt_buf_hold() API to increment the reference
count. Now bt_buf_put() will only put the buffer back to the pool if
the reference count hits 0.

Change-Id: I1590c5574e18600939f55e5339a6da3d061f7682
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
Johan Hedberg 2015-04-30 12:26:01 +03:00 committed by Anas Nashif
commit 89a083f888
2 changed files with 18 additions and 1 deletions

View file

@ -68,6 +68,9 @@ struct bt_buf {
struct bt_buf_acl_data acl;
};
/* Reference count */
uint8_t ref;
/* Type of data contained in the buffer */
uint8_t type;
@ -85,6 +88,9 @@ 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);
/* Increment the reference count of a buffer */
struct bt_buf *bt_buf_hold(struct bt_buf *buf);
/* Prepare data to be added at the end of the buffer */
uint8_t *bt_buf_add(struct bt_buf *buf, size_t len);