24#ifdef XWMM_MEMPOOLLOGF
25# define xwmm_mempoollogf(lv, thd, fmt, ...) \
26 xwlogf(lv, "Thd:%s", fmt, thd->stack.name, ##__VA_ARGS__)
28# define xwmm_mempoollogf(lv, thd, fmt, ...)
85 pgsize = pa->
pgsize << pg_order;
86 nr = pgsize / objsize;
132 for (i = 0; i < loop; i++) {
134 oc->
ctor((
void *)curr);
144 for (i = 0; i < loop; i++) {
279 *objbuf = (
void *)obj;
315 origin = (
xwptr_t)obj - offset;
316 obj = (
void *)origin;
329 if ((reserved + oc->
pg_objnr) <= idleness) {
332 nr = (idleness - reserved) / oc->
pg_objnr;
357 if (capacity < reserved) {
368 }
else if ((reserved + oc->
pg_objnr) < idleness) {
371 nr = (idleness - reserved) / oc->
pg_objnr;
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:初始化对象缓存
xwer_t xwmm_mempool_page_free(struct xwmm_mempool_page_allocator *pa, struct xwmm_mempool_page *pg)
XWMM API:释放一页内存
xwer_t xwmm_mempool_page_allocate(struct xwmm_mempool_page_allocator *pa, xwsq_t order, struct xwmm_mempool_page **pgbuf)
XWMM API:申请一页内存
xwer_t xwmm_mempool_objcache_alloc(struct xwmm_mempool_objcache *oc, void **objbuf)
XWMM API:从对象缓存中申请一个对象
xwer_t xwmm_mempool_objcache_reserve(struct xwmm_mempool_objcache *oc, xwsz_t reserved)
XWMM API:预留对象到对象缓存中
xwer_t xwmm_mempool_objcache_get_capacity(struct xwmm_mempool_objcache *oc, xwsz_t *capacity)
XWMM API:获取对象缓存的容量
xwer_t xwmm_mempool_page_find(struct xwmm_mempool_page_allocator *pa, void *mem, struct xwmm_mempool_page **pgbuf)
依据内存地址查找页
xwer_t xwmm_mempool_objcache_free(struct xwmm_mempool_objcache *oc, void *obj)
XWMM API:释放对象到对象缓存中
static void xwlib_bclst_init_head(struct xwlib_bclst_node *h)
初始化一个链表头。
static void xwlib_bclst_add_tail(struct xwlib_bclst_node *head, struct xwlib_bclst_node *newn)
将一个节点加入链表尾部(链表头的前面)
static void xwlib_bclst_init_node(struct xwlib_bclst_node *n)
初始化一个链表节点。
static bool xwlib_bclst_tst_empty(const struct xwlib_bclst_node *h)
测试链表是否为空。
static void xwlib_bclst_add_head(struct xwlib_bclst_node *head, struct xwlib_bclst_node *newn)
将一个节点加入链表头部(链表头的后面)
static void xwlib_bclst_del_init(struct xwlib_bclst_node *node)
删除一个节点,并重新初始化它
#define xwlib_bclst_last_entry(head, type, member)
获得包含链表最后一个节点的外层结构体的指针。
#define xwlib_bclst_first_entry(head, type, member)
获得包含链表第一个节点的外层结构体的指针。
static void xwlib_lfq_push(atomic_xwlfq_t *h, atomic_xwlfq_t *n)
将一个节点推入无锁队列(栈式队列)
static void xwlib_lfq_init(atomic_xwlfq_t *n)
初始化无锁队列节点
static xwlfq_t * xwlib_lfq_pop(atomic_xwlfq_t *h)
弹出无锁队列中的第一个节点(栈式队列)
__xwcc_atomic xwlfq_t atomic_xwlfq_t
#define xwaop_load(type, a, memorder)
对原子变量进行原子操作:加载
#define xwaop_write(type, a, v, ov)
对原子变量进行原子操作:读取—写
#define xwaop_add(type, a, v, nv, ov)
对原子变量进行原子操作:读取-相加-回写
#define xwaop_sub(type, a, v, nv, ov)
对原子变量进行原子操作:读取-相减-回写
#define XWBOP_DIV_ROUND_UP(n, d)
#define XWBOP_ALIGN(x, n)
static void xwos_sqlk_init(struct xwos_sqlk *sql)
XWOS API:初始化顺序锁
static void xwos_sqlk_wr_lock_cpuirqsv(struct xwos_sqlk *sql, xwreg_t *cpuirq)
XWOS API:开启写临界区,保存本地CPU的中断标志并关闭
static void xwos_sqlk_wr_unlock_cpuirqrs(struct xwos_sqlk *sql, xwreg_t cpuirq)
XWOS API:关闭写临界区,恢复本地CPU的中断标志
static xwsz_t xwmm_mempool_objcache_free_idle_page(struct xwmm_mempool_objcache *oc, xwsz_t nr)
释放空闲页
static xwer_t xwmm_mempool_objcache_page_get(struct xwmm_mempool_objcache *oc, struct xwmm_mempool_page **pgbuf)
获取一页,准备从页内存中分配对象
static xwer_t xwmm_mempool_objcache_i_a_malloc(void *this, xwsz_t size, void **membuf)
i_allocator接口函数:申请内存
static void xwmm_mempool_objcache_page_put(struct xwmm_mempool_objcache *oc, struct xwmm_mempool_page *pg)
减少页的引用计数
static xwer_t xwmm_mempool_objcache_i_a_free(void *this, void *mem)
i_allocator接口函数:释放内存
static void xwmm_mempool_objcache_page_init(struct xwmm_mempool_objcache *oc, struct xwmm_mempool_page *pg)
初始化新页
xwer_t(* free)(void *, void *)
xwer_t(* malloc)(void *, xwsz_t, void **)
struct xwmm_mempool_page_allocator * pa
struct xwlib_bclst_node full
struct xwlib_bclst_node idle
struct xwlib_bclst_node available
struct xwmm_mempool_i_allocator i_a
struct xwmm_mempool_objcache::@0 page_list
struct xwlib_bclst_node node
union xwmm_mempool_page::@1 attr
union xwmm_mempool_page::@2 data
struct xwmm_mempool_page::@1::@4 objcache