21#ifdef XWMM_MEMPOOLLOGF
22# define xwmm_mempoollogf(lv, thd, fmt, ...) \
23 xwlogf(lv, "Thd:%s", fmt, thd->stack.name, ##__VA_ARGS__)
25# define xwmm_mempoollogf(lv, thd, fmt, ...)
101 goto err_oc_128_init;
109 goto err_oc_160_init;
117 goto err_oc_192_init;
125 goto err_oc_256_init;
133 goto err_oc_320_init;
141 goto err_oc_384_init;
149 goto err_oc_512_init;
157 goto err_oc_768_init;
165 goto err_oc_1024_init;
173 goto err_oc_2048_init;
202 xwsz_t pre,
void ** membuf)
215 if (pages_nr != (1U << pgodr)) {
227 goto err_mempool_construct;
233 goto err_mempool_prealloc;
235 if (
NULL != membuf) {
238 }
else if ((
xwptr_t)mp == origin) {
245 goto err_mempool_prealloc;
247 if (
NULL != membuf) {
254err_mempool_construct:
283 ia = (
void *)&mp->
oc_8;
286 ia = (
void *)&mp->
oc_16;
289 ia = (
void *)&mp->
oc_32;
292 ia = (
void *)&mp->
oc_64;
296 ia = (
void *)&mp->
oc_96;
302 if (size <= (
xwsz_t)160) {
304 }
else if (size <= (
xwsz_t)192) {
311 if (size <= (
xwsz_t)320) {
313 }
else if (size <= (
xwsz_t)384) {
320 if (size <= (
xwsz_t)768) {
330 ia = (
void *)&mp->
pa;
333 rc = ia->
malloc(ia, size, membuf);
362 ia = (
void *)&mp->
oc_8;
365 ia = (
void *)&mp->
oc_16;
368 ia = (
void *)&mp->
oc_32;
371 ia = (
void *)&mp->
oc_64;
374 ia = (
void *)&mp->
oc_96;
407 ia = (
void *)&mp->
pa;
410 rc = ia->
free(ia, mem);
425 if (
NULL == *membuf) {
427 }
else if ((
xwsz_t)0 == size) {
440 if (size <= pg->
data.value) {
491 if (size <= alignment) {
503 ia = (
void *)&mp->
oc_8;
506 ia = (
void *)&mp->
oc_16;
509 ia = (
void *)&mp->
oc_32;
512 ia = (
void *)&mp->
oc_64;
530 ia = (
void *)&mp->
pa;
533 rc = ia->
malloc(ia, size, membuf);
static xwer_t xwmm_mempool_construct(struct xwmm_mempool *mp, const char *name, xwptr_t origin, xwsz_t size, struct xwmm_mempool_page_odrbtree *odrbtree, struct xwmm_mempool_page *pgarray)
构建内存池
xwer_t xwmm_mempool_objcache_init(struct xwmm_mempool_objcache *oc, struct xwmm_mempool_page_allocator *pa, const char *name, xwsz_t objsize, xwsz_t alignment, xwsq_t pg_order, ctor_f ctor, dtor_f dtor)
XWMM API:初始化对象缓存
#define XWMM_MEMPOOL_OC_384_PAGE_ODR
#define XWMM_MEMPOOL_OC_128_PAGE_ODR
#define XWMM_MEMPOOL_OC_160_PAGE_ODR
#define XWMM_MEMPOOL_OC_320_PAGE_ODR
#define XWMM_MEMPOOL_OC_256_PAGE_ODR
#define XWMM_MEMPOOL_OC_16_PAGE_ODR
xwer_t xwmm_mempool_malloc(struct xwmm_mempool *mp, xwsz_t size, void **membuf)
XWMM API:从内存池中申请内存
#define XWMM_MEMPOOL_OC_64_PAGE_ODR
xwer_t xwmm_mempool_memalign(struct xwmm_mempool *mp, xwsz_t alignment, xwsz_t size, void **membuf)
XWMM API:从内存池中申请对齐的内存
xwer_t xwmm_mempool_init(struct xwmm_mempool *mp, const char *name, xwptr_t origin, xwsz_t size, xwsz_t pgodr, xwsz_t pre, void **membuf)
XWMM API:初始化内存池
#define XWMM_MEMPOOL_OC_192_PAGE_ODR
#define XWMM_MEMPOOL_OC_8_PAGE_ODR
#define XWMM_MEMPOOL_OC_768_PAGE_ODR
xwer_t xwmm_mempool_page_find(struct xwmm_mempool_page_allocator *pa, void *mem, struct xwmm_mempool_page **pgbuf)
依据内存地址查找页
#define XWMM_MEMPOOL_OC_96_PAGE_ODR
#define XWMM_MEMPOOL_PAGE_SIZE
#define XWMM_MEMPOOL_OC_2048_PAGE_ODR
#define XWMM_MEMPOOL_OC_32_PAGE_ODR
xwer_t xwmm_mempool_free(struct xwmm_mempool *mp, void *mem)
XWMM API:释放内存
xwer_t xwmm_mempool_page_allocator_init(struct xwmm_mempool_page_allocator *pa, const char *name, xwptr_t origin, xwsz_t size, xwsz_t pgsize, struct xwmm_mempool_page_odrbtree *odrbtree, struct xwmm_mempool_page *pgarray)
XWMM API:初始化页分配器
#define XWMM_MEMPOOL_OC_512_PAGE_ODR
#define XWMM_MEMPOOL_OC_1024_PAGE_ODR
xwer_t xwmm_mempool_realloc(struct xwmm_mempool *mp, xwsz_t size, void **membuf)
XWMM API:调整内存大小
#define EINVAL
Invalid argument
#define EFAULT
Bad address
#define xwbop_fls(type, data)
XWOS BOPLIB:在数据中从最高位起查找第一个被置1的位
#define XWBOP_ALIGN(x, n)
#define XWOS_VALIDATE(exp, errstr,...)
检查函数参数是否有效
xwer_t(* free)(void *, void *)
xwer_t(* malloc)(void *, xwsz_t, void **)
union xwmm_mempool_page::@2 data
struct xwmm_mempool_page_allocator pa
struct xwmm_mempool_objcache oc_512
struct xwmm_mempool_objcache oc_32
struct xwmm_mempool_objcache oc_1024
struct xwmm_mempool_objcache oc_768
struct xwmm_mempool_objcache oc_160
struct xwmm_mempool_objcache oc_8
struct xwmm_mempool_objcache oc_192
struct xwmm_mempool_objcache oc_96
struct xwmm_mempool_objcache oc_2048
struct xwmm_mempool_objcache oc_256
struct xwmm_mempool_objcache oc_128
struct xwmm_mempool_objcache oc_384
struct xwmm_mempool_objcache oc_320
struct xwmm_mempool_objcache oc_64
struct xwmm_mempool_objcache oc_16