From af66186dc464918098646cf52444e88483467927 Mon Sep 17 00:00:00 2001 From: Juan Salazar <72028266+regalk13@users.noreply.github.com> Date: Thu, 5 Feb 2026 16:24:17 +0000 Subject: [PATCH 1/3] fix: --count exists without waiting for extra input message --- nmsg/io.c | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/nmsg/io.c b/nmsg/io.c index 9f13fb06..f29f3877 100644 --- a/nmsg/io.c +++ b/nmsg/io.c @@ -741,29 +741,24 @@ io_write(struct nmsg_io_thr *iothr, struct nmsg_io_output *io_output, nmsg_io_t io = iothr->io; nmsg_res res; - /* It's possible a set "count" has been reached. */ - check_close_event(iothr, io_output, 1); - - if (io->stop) { - reset_close_event(iothr, io_output); - nmsg_message_destroy(&msg); - return (nmsg_res_stop); - } res = nmsg_output_write(io_output->output, msg); if (io_output->output->type != nmsg_output_type_callback) nmsg_message_destroy(&msg); - /* - * Reset only after the write, in case another thread invokes - * check_close_event and makes changes to io_output in the meantime. - */ - reset_close_event(iothr, io_output); - if (res != nmsg_res_success) return (res); - + atomic_fetch_add_explicit(&io->io_count_nmsg_payload_out, 1, memory_order_relaxed); + + /* It's possible a set "count" has been reached. */ + check_close_event(iothr, io_output, 1); + reset_close_event(iothr, io_output); + + if (io->stop) { + // nmsg_message_destroy(&msg); + return (nmsg_res_stop); + } return (res); } @@ -797,6 +792,8 @@ check_close_event(struct nmsg_io_thr *iothr, struct nmsg_io_output *io_output, u if (io->count > 0 && io_output->count_next_close == 0) io_output->count_next_close = io->count; + io_output->count_nmsg_payload_out += count; + if (io->count > 0 && io_output->count_nmsg_payload_out == io_output->count_next_close) { @@ -856,13 +853,6 @@ check_close_event(struct nmsg_io_thr *iothr, struct nmsg_io_output *io_output, u } out: - /* - * This incr is implicitly locked IF it's used, and this counter is - * only used IF io->count > 0; that condition results in an acquired - * lock at the beginning of this function. - */ - io_output->count_nmsg_payload_out += count; - if (io->close_fp != NULL || io->count > 0) pthread_mutex_unlock(&io_output->lock); } From 0d7ac2b146890361c1c64dbaa549544e168531a5 Mon Sep 17 00:00:00 2001 From: Juan Salazar <72028266+regalk13@users.noreply.github.com> Date: Tue, 16 Jun 2026 17:39:01 -0500 Subject: [PATCH 2/3] style: fix whitespace --- nmsg/io.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nmsg/io.c b/nmsg/io.c index f29f3877..a445098b 100644 --- a/nmsg/io.c +++ b/nmsg/io.c @@ -748,9 +748,9 @@ io_write(struct nmsg_io_thr *iothr, struct nmsg_io_output *io_output, if (res != nmsg_res_success) return (res); - + atomic_fetch_add_explicit(&io->io_count_nmsg_payload_out, 1, memory_order_relaxed); - + /* It's possible a set "count" has been reached. */ check_close_event(iothr, io_output, 1); reset_close_event(iothr, io_output); From 2fbf63027689bb263524cff8381739e37ce7e29e Mon Sep 17 00:00:00 2001 From: Juan Salazar <72028266+regalk13@users.noreply.github.com> Date: Mon, 22 Jun 2026 10:57:19 -0500 Subject: [PATCH 3/3] clean destroy commented function --- nmsg/io.c | 1 - 1 file changed, 1 deletion(-) diff --git a/nmsg/io.c b/nmsg/io.c index a445098b..d8123b69 100644 --- a/nmsg/io.c +++ b/nmsg/io.c @@ -756,7 +756,6 @@ io_write(struct nmsg_io_thr *iothr, struct nmsg_io_output *io_output, reset_close_event(iothr, io_output); if (io->stop) { - // nmsg_message_destroy(&msg); return (nmsg_res_stop); }