summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_mp.c
diff options
context:
space:
mode:
authorMax Romanov <max.romanov@nginx.com>2017-07-18 00:21:16 +0300
committerMax Romanov <max.romanov@nginx.com>2017-07-18 00:21:16 +0300
commit803855138c3b714c088e42a32e80939a81785944 (patch)
treef19efadd82ecfb2aa42f93a1fa67c451ca690724 /src/nxt_mp.c
parenteb675f2d78178b2cdd54d934022f9b739bfa8952 (diff)
downloadunit-803855138c3b714c088e42a32e80939a81785944.tar.gz
unit-803855138c3b714c088e42a32e80939a81785944.tar.bz2
Mem pool cleanup introduced.
Used for connection mem pool cleanup, which can be used by buffers. Used for port mem pool to safely destroy linked process.
Diffstat (limited to '')
-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;
+}