MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / _ObjectPool_ReuseItem

Function _ObjectPool_ReuseItem

src/util/object_pool/object_pool.c:63–80  ·  view source on GitHub ↗

Clear a deleted item and recycle it to the caller.

Source from the content-addressed store, hash-verified

61
62// Clear a deleted item and recycle it to the caller.
63static void *_ObjectPool_ReuseItem(ObjectPool *pool) {
64 ObjectID idx = array_pop(pool->deletedIdx);
65
66 pool->itemCount++;
67
68 Block *block = GET_ITEM_BLOCK(pool, idx);
69 uint pos = ITEM_POSITION_WITHIN_BLOCK(idx);
70
71 // Retrieve a pointer to the item's header.
72 unsigned char *item_header = block->data + (pos * block->itemSize);
73 unsigned char *item = ITEM_FROM_HEADER(item_header);
74 ASSERT(ITEM_ID(item) == idx); // The item ID should not change on reuse.
75
76 // Zero-set the item being returned.
77 memset(item, 0, block->itemSize - HEADER_SIZE);
78
79 return item;
80}
81
82ObjectPool *ObjectPool_New(uint64_t itemCap, uint itemSize, void (*fp)(void *)) {
83 ObjectPool *pool = rm_malloc(sizeof(ObjectPool));

Callers 1

ObjectPool_NewItemFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected