diff --git a/inc/tlpbuf.h b/inc/tlpbuf.h index 17e9767..c799a03 100644 --- a/inc/tlpbuf.h +++ b/inc/tlpbuf.h @@ -16,7 +16,7 @@ #endif -typedef void (*pbuf_callback_t)(void); //function pointer that will be called when a pbuf is freed in this pool +typedef void (*pbuf_callback_t)(void*); //function pointer that will be called when a pbuf is freed in this pool struct pbuf_pool_s; @@ -28,10 +28,10 @@ uint32_t capacity; uint8_t* payload_memory; - struct pbuf_s *next; //used to link pbufs - struct pbuf_pool_s *pool; + struct pbuf_s* next; //used to link pbufs + struct pbuf_pool_s* pool; - void *user; + void* user; }pbuf_t; @@ -48,6 +48,7 @@ pbuf_t* free_list; pbuf_callback_t free_callback; + void* free_callback_user; }pbuf_pool_t; @@ -86,33 +87,33 @@ payload_memory needs to be a statically allocated memory chunk of size: pbuf_count * pbuf_payload_size (bytes) */ -void pbuf_pool_create(pbuf_pool_t *pool, uint32_t pbuf_count, void *pbuf_memory, uint32_t payload_capacity, void *payload_memory); -void pbuf_pool_reset(pbuf_pool_t *pool); +void pbuf_pool_create(pbuf_pool_t *pool, uint32_t pbuf_count, void* pbuf_memory, uint32_t payload_capacity, void* payload_memory); +void pbuf_pool_reset(pbuf_pool_t* pool); -void pbuf_dump_pool(pbuf_pool_t *pool); +void pbuf_dump_pool(pbuf_pool_t* pool); -static inline uint32_t pbuf_pool_get_available(pbuf_pool_t *pool) +static inline uint32_t pbuf_pool_get_available(pbuf_pool_t* pool) { return pool->pbufs_available; } -static inline void pbuf_reset(pbuf_t *p) +static inline void pbuf_reset(pbuf_t* p) { p->payload = p->payload_memory; p->capacity = p->pool->payload_capacity; } -static inline uint32_t pbuf_offset(pbuf_t *p) +static inline uint32_t pbuf_offset(pbuf_t* p) { return p->payload - p->payload_memory; } -static inline pbuf_t* pbuf_alloc(pbuf_pool_t *pool) +static inline pbuf_t* pbuf_alloc(pbuf_pool_t* pool) { assert(pool); @@ -139,7 +140,7 @@ p->pool->pbufs_available++; if (p->pool->free_callback) //call the hook if we have one - p->pool->free_callback(); + p->pool->free_callback(p->pool->free_callback_user); } } diff --git a/src/tlpbuf.c b/src/tlpbuf.c index 21a6722..3bb9f53 100644 --- a/src/tlpbuf.c +++ b/src/tlpbuf.c @@ -1,7 +1,7 @@ #include -void pbuf_pool_create(pbuf_pool_t *pool, uint32_t pbuf_count, void *pbuf_memory, uint32_t pbuf_payload_capacity, void *pbuf_payload_memory) +void pbuf_pool_create(pbuf_pool_t* pool, uint32_t pbuf_count, void* pbuf_memory, uint32_t pbuf_payload_capacity, void* pbuf_payload_memory) { assert(pool); assert(pbuf_count); @@ -23,7 +23,7 @@ -void pbuf_pool_reset(pbuf_pool_t *pool) +void pbuf_pool_reset(pbuf_pool_t* pool) { assert(pool); @@ -51,7 +51,7 @@ /* -void pbuf_dump_pool(pbuf_pool_t *pool) +void pbuf_dump_pool(pbuf_pool_t* pool) { debug_printf("\r\nPool %x, %u pbufs available\r\n", pool, pool->pbufs_available);