summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/nxt_application.c2
-rw-r--r--src/nxt_buf.c7
-rw-r--r--src/nxt_conn.c6
-rw-r--r--src/nxt_mp.c59
-rw-r--r--src/nxt_mp.h25
-rw-r--r--src/nxt_port.c2
-rw-r--r--src/nxt_port_memory.c8
-rw-r--r--src/nxt_port_socket.c11
-rw-r--r--src/nxt_router.c17
9 files changed, 72 insertions, 65 deletions
diff --git a/src/nxt_application.c b/src/nxt_application.c
index a854564e..29b7a1e6 100644
--- a/src/nxt_application.c
+++ b/src/nxt_application.c
@@ -892,7 +892,7 @@ nxt_app_http_req_body_read(nxt_task_t *task, nxt_app_parse_ctx_t *ctx,
nxt_int_t
nxt_app_http_req_done(nxt_task_t *task, nxt_app_parse_ctx_t *ctx)
{
- nxt_mp_release(ctx->mem_pool, NULL);
+ nxt_mp_release(ctx->mem_pool);
return NXT_OK;
}
diff --git a/src/nxt_buf.c b/src/nxt_buf.c
index 7bc983a3..36a1dcd0 100644
--- a/src/nxt_buf.c
+++ b/src/nxt_buf.c
@@ -59,11 +59,13 @@ nxt_buf_mem_ts_alloc(nxt_task_t *task, nxt_mp_t *mp, size_t size)
nxt_buf_t *b;
nxt_buf_ts_t *ts;
- b = nxt_mp_retain(mp, NXT_BUF_MEM_SIZE + sizeof(nxt_buf_ts_t) + size);
+ b = nxt_mp_alloc(mp, NXT_BUF_MEM_SIZE + sizeof(nxt_buf_ts_t) + size);
if (nxt_slow_path(b == NULL)) {
return NULL;
}
+ nxt_mp_retain(mp);
+
nxt_memzero(b, NXT_BUF_MEM_SIZE + sizeof(nxt_buf_ts_t));
b->data = mp;
@@ -284,7 +286,8 @@ nxt_buf_ts_completion(nxt_task_t *task, void *obj, void *data)
#endif
mp = b->data;
- nxt_mp_release(mp, b);
+ nxt_mp_free(mp, b);
+ nxt_mp_release(mp);
if (parent != NULL) {
nxt_debug(task, "parent retain:%uD", parent->retain);
diff --git a/src/nxt_conn.c b/src/nxt_conn.c
index 9d30fcfd..854181ca 100644
--- a/src/nxt_conn.c
+++ b/src/nxt_conn.c
@@ -96,9 +96,13 @@ nxt_conn_create(nxt_mp_t *mp, nxt_task_t *task)
void
nxt_conn_free(nxt_task_t *task, nxt_conn_t *c)
{
+ nxt_mp_t *mp;
+
task->thread->engine->connections--;
- nxt_mp_release(c->mem_pool, c);
+ mp = c->mem_pool;
+ nxt_mp_free(mp, c);
+ nxt_mp_release(mp);
}
diff --git a/src/nxt_mp.c b/src/nxt_mp.c
index 8c2da262..776c96b2 100644
--- a/src/nxt_mp.c
+++ b/src/nxt_mp.c
@@ -282,6 +282,28 @@ nxt_mp_create(size_t cluster_size, size_t page_alignment, size_t page_size,
void
+nxt_mp_retain(nxt_mp_t *mp)
+{
+ mp->retain++;
+
+ nxt_thread_log_debug("mp %p retain: %uD", mp, mp->retain);
+}
+
+
+void
+nxt_mp_release(nxt_mp_t *mp)
+{
+ mp->retain--;
+
+ nxt_thread_log_debug("mp %p release: %uD", mp, mp->retain);
+
+ if (mp->retain == 0) {
+ nxt_mp_destroy(mp);
+ }
+}
+
+
+void
nxt_mp_destroy(nxt_mp_t *mp)
{
void *p;
@@ -934,43 +956,6 @@ nxt_mp_chunk_free(nxt_mp_t *mp, nxt_mp_block_t *cluster, u_char *p)
void *
-nxt_mp_retain(nxt_mp_t *mp, size_t size)
-{
- void *p;
-
- p = nxt_mp_alloc(mp, size);
-
- if (nxt_fast_path(p != NULL)) {
- mp->retain++;
- nxt_debug_alloc("mp %p retain: %uD", mp, mp->retain);
- }
-
- return p;
-}
-
-
-uint32_t
-nxt_mp_release(nxt_mp_t *mp, void *p)
-{
- if (nxt_fast_path(p != NULL)) {
- nxt_mp_free(mp, p);
- }
-
- mp->retain--;
-
- nxt_debug_alloc("mp %p release: %uD", mp, mp->retain);
-
- if (mp->retain == 0) {
- nxt_mp_destroy(mp);
-
- return 0;
- }
-
- return mp->retain;
-}
-
-
-void *
nxt_mp_nget(nxt_mp_t *mp, size_t size)
{
void *p;
diff --git a/src/nxt_mp.h b/src/nxt_mp.h
index 71a48de6..53d1f011 100644
--- a/src/nxt_mp.h
+++ b/src/nxt_mp.h
@@ -41,6 +41,17 @@ NXT_EXPORT nxt_mp_t *nxt_mp_create(size_t cluster_size, size_t page_alignment,
*/
NXT_EXPORT void nxt_mp_destroy(nxt_mp_t *mp);
+/*
+ * nxt_mp_retain() increases memory pool retention counter.
+ */
+NXT_EXPORT void nxt_mp_retain(nxt_mp_t *mp);
+
+/*
+ * nxt_mp_release() decreases memory pool retention counter.
+ * If the counter becomes zero the pool is destroyed.
+ */
+NXT_EXPORT void nxt_mp_release(nxt_mp_t *mp);
+
/* nxt_mp_test_sizes() tests validity of memory pool parameters. */
NXT_EXPORT nxt_bool_t nxt_mp_test_sizes(size_t cluster_size,
size_t page_alignment, size_t page_size, size_t min_chunk_size);
@@ -76,20 +87,6 @@ NXT_EXPORT void *nxt_mp_zalign(nxt_mp_t *mp, size_t alignment, size_t size)
NXT_EXPORT void nxt_mp_free(nxt_mp_t *mp, void *p);
-/*
- * nxt_mp_retain() returns aligned freeable memory and increases memory
- * pool retention counter.
- */
-NXT_EXPORT void *nxt_mp_retain(nxt_mp_t *mp, size_t size)
- NXT_MALLOC_LIKE;
-
-/*
- * nxt_mp_release() returns freeable memory and decreases memory pool
- * retention counter. If the counter becomes zero the pool is destroyed.
- */
-NXT_EXPORT uint32_t nxt_mp_release(nxt_mp_t *mp, void *p);
-
-
/* nxt_mp_nget() returns non-aligned non-freeable memory. */
NXT_EXPORT void *nxt_mp_nget(nxt_mp_t *mp, size_t size)
NXT_MALLOC_LIKE;
diff --git a/src/nxt_port.c b/src/nxt_port.c
index 5a1d4e6c..e8e94a94 100644
--- a/src/nxt_port.c
+++ b/src/nxt_port.c
@@ -120,7 +120,7 @@ nxt_port_release(nxt_task_t *task, nxt_port_t *port)
nxt_process_use(task, port->process, -1);
}
- nxt_mp_release(port->mem_pool, NULL);
+ nxt_mp_release(port->mem_pool);
}
diff --git a/src/nxt_port_memory.c b/src/nxt_port_memory.c
index 3a1ec198..7be4347a 100644
--- a/src/nxt_port_memory.c
+++ b/src/nxt_port_memory.c
@@ -173,7 +173,8 @@ release_buf:
nxt_port_mmap_handler_use(mmap_handler, -1);
- nxt_mp_release(mp, b);
+ nxt_mp_free(mp, b);
+ nxt_mp_release(mp);
}
@@ -588,6 +589,7 @@ nxt_buf_t *
nxt_port_mmap_get_buf(nxt_task_t *task, nxt_port_t *port, size_t size)
{
size_t nchunks;
+ nxt_mp_t *mp;
nxt_buf_t *b;
nxt_chunk_id_t c;
nxt_port_mmap_header_t *hdr;
@@ -605,7 +607,9 @@ nxt_port_mmap_get_buf(nxt_task_t *task, nxt_port_t *port, size_t size)
mmap_handler = nxt_port_mmap_get(task, port, &c, 0);
if (nxt_slow_path(mmap_handler == NULL)) {
- nxt_mp_release(task->thread->engine->mem_pool, b);
+ mp = task->thread->engine->mem_pool;
+ nxt_mp_free(mp, b);
+ nxt_mp_release(mp);
return NULL;
}
diff --git a/src/nxt_port_socket.c b/src/nxt_port_socket.c
index 34e57a3c..c3485bdb 100644
--- a/src/nxt_port_socket.c
+++ b/src/nxt_port_socket.c
@@ -159,21 +159,26 @@ nxt_port_release_send_msg(nxt_task_t *task, void *obj, void *data)
return;
}
- nxt_mp_release(engine->mem_pool, obj);
+ nxt_mp_free(engine->mem_pool, obj);
+ nxt_mp_release(engine->mem_pool);
}
static nxt_port_send_msg_t *
nxt_port_msg_create(nxt_task_t *task, nxt_port_send_msg_t *m)
{
+ nxt_mp_t *mp;
nxt_port_send_msg_t *msg;
- msg = nxt_mp_retain(task->thread->engine->mem_pool,
- sizeof(nxt_port_send_msg_t));
+ mp = task->thread->engine->mem_pool;
+
+ msg = nxt_mp_alloc(mp, sizeof(nxt_port_send_msg_t));
if (nxt_slow_path(msg == NULL)) {
return NULL;
}
+ nxt_mp_retain(mp);
+
msg->link.next = NULL;
msg->link.prev = NULL;
diff --git a/src/nxt_router.c b/src/nxt_router.c
index f20fc6aa..66ad6478 100644
--- a/src/nxt_router.c
+++ b/src/nxt_router.c
@@ -270,6 +270,7 @@ nxt_router_start_worker_handler(nxt_task_t *task, nxt_port_t *port, void *data)
{
size_t size;
uint32_t stream;
+ nxt_mp_t *mp;
nxt_app_t *app;
nxt_buf_t *b;
nxt_port_t *main_port;
@@ -300,7 +301,9 @@ nxt_router_start_worker_handler(nxt_task_t *task, nxt_port_t *port, void *data)
-1, app);
if (nxt_slow_path(stream == 0)) {
- nxt_mp_release(b->data, b);
+ mp = b->data;
+ nxt_mp_free(mp, b);
+ nxt_mp_release(mp);
goto failed;
}
@@ -389,7 +392,7 @@ nxt_router_ra_create(nxt_task_t *task, nxt_req_app_link_t *ra_src)
mp = ra_src->ap->mem_pool;
- ra = nxt_mp_retain(mp, sizeof(nxt_req_app_link_t));
+ ra = nxt_mp_alloc(mp, sizeof(nxt_req_app_link_t));
if (nxt_slow_path(ra == NULL)) {
@@ -399,6 +402,8 @@ nxt_router_ra_create(nxt_task_t *task, nxt_req_app_link_t *ra_src)
return NULL;
}
+ nxt_mp_retain(mp);
+
nxt_router_ra_init(task, ra, ra_src->rc);
ra->mem_pool = mp;
@@ -497,6 +502,7 @@ nxt_router_ra_update_peer(nxt_task_t *task, nxt_req_app_link_t *ra)
static void
nxt_router_ra_release(nxt_task_t *task, nxt_req_app_link_t *ra)
{
+ nxt_mp_t *mp;
nxt_conn_t *c;
nxt_req_conn_link_t *rc;
@@ -539,8 +545,11 @@ nxt_router_ra_release(nxt_task_t *task, nxt_req_app_link_t *ra)
nxt_router_msg_cancel(task, &ra->msg_info, ra->stream);
- if (ra->mem_pool != NULL) {
- nxt_mp_release(ra->mem_pool, ra);
+ mp = ra->mem_pool;
+
+ if (mp != NULL) {
+ nxt_mp_free(mp, ra);
+ nxt_mp_release(mp);
}
}