uint32_t page_alignment;
uint32_t cluster_size;
+ njs_mp_cleanup_t *cleanup;
+
njs_mp_slot_t slots[];
};
{
void *p;
njs_mp_block_t *block;
+ njs_mp_cleanup_t *c;
njs_rbtree_node_t *node, *next;
njs_debug_alloc("mp destroy\n");
+ for (c = mp->cleanup; c != NULL; c = c->next) {
+ if (c->handler != NULL) {
+ njs_debug_alloc("mp run cleanup: @%p\n", c);
+ c->handler(c->data);
+ }
+ }
+
next = njs_rbtree_root(&mp->blocks);
while (next != njs_rbtree_sentinel(&mp->blocks)) {
}
+njs_mp_cleanup_t *
+njs_mp_cleanup_add(njs_mp_t *mp, size_t size)
+{
+ njs_mp_cleanup_t *c;
+
+ c = njs_mp_alloc(mp, sizeof(njs_mp_cleanup_t));
+ if (njs_slow_path(c == NULL)) {
+ return NULL;
+ }
+
+ if (size) {
+ c->data = njs_mp_alloc(mp, size);
+ if (njs_slow_path(c->data == NULL)) {
+ return NULL;
+ }
+
+ } else {
+ c->data = NULL;
+ }
+
+ c->handler = NULL;
+ c->next = mp->cleanup;
+
+ mp->cleanup = c;
+
+ njs_debug_alloc("mp add cleanup: @%p\n", c);
+
+ return c;
+}
+
+
void
njs_mp_free(njs_mp_t *mp, void *p)
{
typedef struct njs_mp_s njs_mp_t;
+typedef struct njs_mp_cleanup_s njs_mp_cleanup_t;
+
+typedef void (*njs_mp_cleanup_pt)(void *data);
+
+struct njs_mp_cleanup_s {
+ njs_mp_cleanup_pt handler;
+ void *data;
+ njs_mp_cleanup_t *next;
+};
NJS_EXPORT njs_mp_t *njs_mp_create(size_t cluster_size, size_t page_alignment,
NJS_EXPORT void *njs_mp_zalign(njs_mp_t *mp,
size_t alignment, size_t size)
NJS_MALLOC_LIKE;
+NJS_EXPORT njs_mp_cleanup_t *njs_mp_cleanup_add(njs_mp_t *mp, size_t size);
NJS_EXPORT void njs_mp_free(njs_mp_t *mp, void *p);