3#include "valgrind/helgrind.h"
8#define MPHUGE (64 * SZ_INT)
9#define BLK(obj_sz) (obj_sz < MPHUGE ? SMALL_BLK : BIG_BLK)
31 p->
data = (uint8_t **)
xcalloc(1,
sizeof(uint8_t *));
40 for (
size_t j =
SZ_INT, k = 0; sz >= k; k = j, j <<= 1) p->
sizes[p->
sz++] = j;
67 for (
size_t i = 0; i < mp->
sz; ++i) {
68 if (obj_sz <= mp->sizes[i])
86 for (uint32_t i =
nblk; i < p->
nblk; ++i)
96 VALGRIND_HG_CLEAN_MEMORY(recycle, p->
obj_sz);
99 if (zero) memset((
void*)recycle, 0, p->
obj_sz);
100 return (
void*)recycle;
117 memset(ptr, 0, p->
obj_sz);
138#define MP_ALLOC(name, zero, default) \
139 void *_mp_##name(MemPool mp, const m_uint size) { \
140 struct pool *p = mp_ini(mp, size); \
141 void * ret = p ? _mp_calloc2(p, zero) : (void *)default; \
150 if (ret != ptr) memcpy(ret, ptr, curr);
meta header (use this to include the whole library)
ANN struct pool * mp_ini(MemPool mp, const uint32_t obj_sz)
void * _mp_calloc2(struct pool *p, const bool zero)
void mp_end(struct pool *p)
static ANN void mp_set(struct pool *p, const uint32_t obj_sz)
void * mp_realloc(MemPool mp, void *ptr, const m_uint curr, const m_uint next)
static void * __mp_calloc2(struct pool *p, const bool zero)
#define MP_ALLOC(name, zero, default)
MemPool mempool_ini(const size_t sz)
void _mp_free2(struct pool *p, void *ptr)
void mempool_end(MemPool mp)
void _mp_free(MemPool mp, const m_uint size, void *ptr)
struct pool * new_pool(const uint32_t obj_sz)
static void _realloc(struct pool *p)
static struct pool * mp_create(MemPool mp, const uint32_t obj_sz, const uint32_t idx)
#define mp_free2(p, sz, a)
ANEW ANN void * _mp_malloc(MemPool, const m_uint) __attribute__((hot))
struct MemPool_ * MemPool
struct pool * master_pool
volatile struct Recycle * next
volatile struct Recycle * next
pthread_mutex_t gwtlock_t
static ANN int gwt_unlock(gwtlock_t *lock)
static ANN void gwt_lock_end(gwtlock_t *lock)
static ANN int gwt_lock_ini(gwtlock_t *lock)
static ANN int gwt_lock(gwtlock_t *lock)
static ANEW void * xcalloc(const m_uint n, const m_uint sz)
static ANEW void * xmalloc(const m_uint sz)
static ANEW void * xrealloc(void *p, const m_uint sz)