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.
This commit is contained in:
Max Romanov
2017-07-18 00:21:16 +03:00
parent eb675f2d78
commit 803855138c
9 changed files with 104 additions and 39 deletions

View File

@@ -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;
}