summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_mp.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nxt_mp.c')
-rw-r--r--src/nxt_mp.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/nxt_mp.c b/src/nxt_mp.c
index 57fe4f09..40d12be0 100644
--- a/src/nxt_mp.c
+++ b/src/nxt_mp.c
@@ -114,6 +114,8 @@ struct nxt_mp_s {
nxt_tid_t tid;
#endif
+ nxt_work_t *cleanup;
+
/* Lists of nxt_mp_page_t. */
nxt_queue_t free_pages;
nxt_queue_t nget_pages;
@@ -283,6 +285,7 @@ void
nxt_mp_destroy(nxt_mp_t *mp)
{
void *p;
+ nxt_work_t *work, *next_work;
nxt_mp_block_t *block;
nxt_rbtree_node_t *node, *next;
@@ -290,6 +293,15 @@ nxt_mp_destroy(nxt_mp_t *mp)
nxt_mp_thread_assert(mp);
+ while (mp->cleanup != NULL) {
+ work = mp->cleanup;
+ next_work = work->next;
+
+ work->handler(work->task, work->obj, work->data);
+
+ mp->cleanup = next_work;
+ }
+
next = nxt_rbtree_root(&mp->blocks);
while (next != nxt_rbtree_sentinel(&mp->blocks)) {
@@ -1022,3 +1034,27 @@ nxt_mp_zget(nxt_mp_t *mp, size_t size)
return p;
}
+
+
+nxt_int_t
+nxt_mp_cleanup(nxt_mp_t *mp, nxt_work_handler_t handler,
+ nxt_task_t *task, void *obj, void *data)
+{
+ nxt_work_t *work;
+
+ work = nxt_mp_get(mp, sizeof(nxt_work_t));
+
+ if (nxt_slow_path(work == NULL)) {
+ return NXT_ERROR;
+ }
+
+ work->next = mp->cleanup;
+ work->handler = handler;
+ work->task = task;
+ work->obj = obj;
+ work->data = data;
+
+ mp->cleanup = work;
+
+ return NXT_OK;
+}