17#include <zephyr/kernel.h>
18#include <zephyr/sys/__assert.h>
19#include <zephyr/bluetooth/conn.h>
31#define BT_CONN_CTX_DEF(_name, _max_clients, _ctx_sz) \
32 K_MEM_SLAB_DEFINE(_name##_mem_slab, \
33 ROUND_UP(_ctx_sz, CONFIG_BT_CONN_CTX_MEM_BUF_ALIGN), \
35 CONFIG_BT_CONN_CTX_MEM_BUF_ALIGN); \
36 K_MUTEX_DEFINE(_name##_mutex); \
37 static struct bt_conn_ctx_lib _CONCAT(_name, _ctx_lib) = \
39 .mem_slab = &_CONCAT(_name, _mem_slab), \
40 .mutex = &_name##_mutex \
74 return ctx_lib->
mem_slab->info.block_size;
86 return ARRAY_SIZE(ctx_lib->
ctx);
static size_t bt_conn_ctx_block_size_get(struct bt_conn_ctx_lib *ctx_lib)
Get the block size.
Definition conn_ctx.h:72
const struct bt_conn_ctx * bt_conn_ctx_get_by_id(struct bt_conn_ctx_lib *ctx_lib, uint8_t id)
Get a specific connection context from the memory pool.
void * bt_conn_ctx_alloc(struct bt_conn_ctx_lib *ctx_lib, struct bt_conn *conn)
Allocate memory for the connection context data.
void bt_conn_ctx_release(struct bt_conn_ctx_lib *ctx_lib, void *data)
Release a connection context from the memory pool.
void * bt_conn_ctx_get(struct bt_conn_ctx_lib *ctx_lib, struct bt_conn *conn)
Get the context data of a connection from the memory pool.
static size_t bt_conn_ctx_count(struct bt_conn_ctx_lib *ctx_lib)
Get the number of connection contexts that are managed by the library.
Definition conn_ctx.h:84
void bt_conn_ctx_free_all(struct bt_conn_ctx_lib *ctx_lib)
Free all allocated context data.
int bt_conn_ctx_free(struct bt_conn_ctx_lib *ctx_lib, struct bt_conn *conn)
Free the allocated memory for a connection.
struct bt_conn_ctx ctx[CONFIG_BT_MAX_CONN]
Definition conn_ctx.h:55
struct k_mem_slab *const mem_slab
Definition conn_ctx.h:62
struct k_mutex *const mutex
Definition conn_ctx.h:59
Bluetooth connection context library structure.
Definition conn_ctx.h:53
struct bt_conn * conn
Definition conn_ctx.h:49
void * data
Definition conn_ctx.h:46
Context data for a connection.
Definition conn_ctx.h:44