Skip to content

Commit

Permalink
fix pool: fix mem pool style and add pcallc
Browse files Browse the repository at this point in the history
  • Loading branch information
ffashion committed Feb 29, 2024
1 parent 817d80a commit 7cb08a5
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 32 deletions.
6 changes: 5 additions & 1 deletion src/adb/packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,11 @@ void xdbd_dump_adb_packet(xdbd_pool_t *pool, const xdbd_adb_packet_t *p) {
hex_payload.size = xdbd_buf_size(p->payload);

payload = xdbd_dump_hex(pool, hex_payload);

if (payload == NULL) {
// bfdev_log_debug("payload is null\n");
// return;
}
bfdev_log_debug("%p", payload);
bfdev_log_debug("%.*s\n", (int)xdbd_buf_size(payload), payload->pos);
return;
}
2 changes: 1 addition & 1 deletion src/adb/xdbd_adb.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ int xdbd_adb_parse_adb_header(xdbd_adb_request_t *r, xdbd_buf_t *b) {

xdbd_memcpy(&r->h, b->start, sizeof(xdbd_adb_header_t));

r->p = xdbd_palloc(r->temp_pool, sizeof(xdbd_adb_packet_t));
r->p = xdbd_pcalloc(r->temp_pool, sizeof(xdbd_adb_packet_t));
if (r->p == NULL) {
return XDBD_ERR;
}
Expand Down
2 changes: 1 addition & 1 deletion src/adb/xdbd_adb_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xdbd_adb_request_t *xdbd_adb_create_request(xdbd_connection_t *c) {
xdbd_adb_request_t *r;

r = xdbd_palloc(c->pool, sizeof(xdbd_adb_request_t));
r = xdbd_pcalloc(c->pool, sizeof(xdbd_adb_request_t));
if (r == NULL) {
return NULL;
}
Expand Down
36 changes: 18 additions & 18 deletions src/core/xdbd_pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
#include <xdbd.h>
#include <bfdev/align.h>
#include <bfdev/bug.h>
#include <string.h>

static inline void *
cache_alloc(xdbd_pool_t *pool, size_t size)
{
static inline void *cache_alloc(xdbd_pool_t *pool, size_t size) {
xdbd_cache_t *cache;
void *retval;

Expand Down Expand Up @@ -42,9 +41,7 @@ cache_alloc(xdbd_pool_t *pool, size_t size)
return retval;
}

static inline void *
block_alloc(xdbd_pool_t *pool, size_t size)
{
static inline void *block_alloc(xdbd_pool_t *pool, size_t size) {
xdbd_block_t *block;
void *retval;

Expand All @@ -66,18 +63,25 @@ block_alloc(xdbd_pool_t *pool, size_t size)
return retval;
}

void *
xdbd_palloc(xdbd_pool_t *pool, size_t size)
{
void *xdbd_palloc(xdbd_pool_t *pool, size_t size) {
if (size < XDBD_PAGE_SIZE)
return cache_alloc(pool, size);

return block_alloc(pool, size);
}

xdbd_pool_t *
xdbd_create_pool()
{
void *xdbd_pcalloc(xdbd_pool_t *pool, size_t size) {
void *p;
p = xdbd_palloc(pool, size);
if (p == NULL) {
return NULL;
}

xdbd_memzero(p, size);
return p;
}

xdbd_pool_t *xdbd_create_pool() {
xdbd_pool_t *pool;

pool = bfdev_malloc(NULL, sizeof(*pool));
Expand All @@ -90,9 +94,7 @@ xdbd_create_pool()
return pool;
}

void
xdbd_release_pool(xdbd_pool_t *pool)
{
void xdbd_release_pool(xdbd_pool_t *pool) {
xdbd_cache_t *cache, *tcache;
xdbd_block_t *block, *tblock;

Expand All @@ -110,9 +112,7 @@ xdbd_release_pool(xdbd_pool_t *pool)
bfdev_slist_head_init(&pool->block);
}

void
xdbd_destroy_pool(xdbd_pool_t *pool)
{
void xdbd_destroy_pool(xdbd_pool_t *pool) {
xdbd_release_pool(pool);
bfdev_free(NULL, pool);
}
16 changes: 5 additions & 11 deletions src/core/xdbd_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,10 @@ struct xdbd_block {
void *data;
};

extern __bfdev_malloc void *
xdbd_palloc(xdbd_pool_t *pool, size_t size);

extern xdbd_pool_t *
xdbd_create_pool();

extern void
xdbd_release_pool(xdbd_pool_t *pool);

extern void
xdbd_destroy_pool(xdbd_pool_t *pool);
__bfdev_malloc void *xdbd_palloc(xdbd_pool_t *pool, size_t size);
void *xdbd_pcalloc(xdbd_pool_t *pool, size_t size);
xdbd_pool_t *xdbd_create_pool();
void xdbd_release_pool(xdbd_pool_t *pool);
void xdbd_destroy_pool(xdbd_pool_t *pool);

#endif /*__XDBD_POOL__H__*/

0 comments on commit 7cb08a5

Please sign in to comment.