From a5508cec7a55fe04ab66451c7510fab0e0d4577c Mon Sep 17 00:00:00 2001 From: Max Romanov Date: Wed, 28 Oct 2020 00:01:46 +0300 Subject: [PATCH] Libunit: added a function to discern main and worker contexts. --- src/nxt_unit.c | 11 +++++++++++ src/nxt_unit.h | 2 ++ 2 files changed, 13 insertions(+) diff --git a/src/nxt_unit.c b/src/nxt_unit.c index 4b0f5230..6a0657c6 100644 --- a/src/nxt_unit.c +++ b/src/nxt_unit.c @@ -4854,6 +4854,17 @@ nxt_unit_run_shared(nxt_unit_ctx_t *ctx) } +int +nxt_unit_is_main_ctx(nxt_unit_ctx_t *ctx) +{ + nxt_unit_impl_t *lib; + + lib = nxt_container_of(ctx->unit, nxt_unit_impl_t, unit); + + return (ctx == &lib->main_ctx.ctx); +} + + int nxt_unit_process_port_msg(nxt_unit_ctx_t *ctx, nxt_unit_port_t *port) { diff --git a/src/nxt_unit.h b/src/nxt_unit.h index 52f9bc27..303d5aa1 100644 --- a/src/nxt_unit.h +++ b/src/nxt_unit.h @@ -210,6 +210,8 @@ int nxt_unit_run_ctx(nxt_unit_ctx_t *ctx); int nxt_unit_run_shared(nxt_unit_ctx_t *ctx); +int nxt_unit_is_main_ctx(nxt_unit_ctx_t *ctx); + /* * Receive and process one message, invoke configured callbacks. *