public inbox for [email protected]
 help / color / mirror / Atom feed
From: Ammar Faizi <[email protected]>
To: Alviro Iskandar Setiawan <[email protected]>
Cc: Ammar Faizi <[email protected]>,
	Muhammad Rizki <[email protected]>,
	GNU/Weeb Mailing List <[email protected]>
Subject: [PATCH ncns v1 1/2] chnet: Optimize `put_thread()` path
Date: Wed, 19 Oct 2022 23:43:08 +0700	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>

The `delete` call doesn't have to be protected by mutex. Move it
to the outside of the locked region to reduce the `put_thread()`
critical section time.

Signed-off-by: Ammar Faizi <[email protected]>
---
 chnet/chnet.cc | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/chnet/chnet.cc b/chnet/chnet.cc
index e6b4c64..ba3c076 100644
--- a/chnet/chnet.cc
+++ b/chnet/chnet.cc
@@ -746,10 +746,13 @@ static void put_thread(void *thread)
 	if (--th->ref_count_ == 0) {
 		if (g_thpool)
 			g_thpool[th->idx_] = nullptr;
-
-		delete th;
+	} else {
+		th = nullptr;
 	}
 	g_thpool_lock_.unlock();
+
+	if (th)
+		delete th;
 }
 
 static void init_g_ch_thpool(void)
-- 
Ammar Faizi


  reply	other threads:[~2022-10-19 16:43 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-19 16:43 [PATCH ncns v1 0/2] Small optimization and improve debugging experience Ammar Faizi
2022-10-19 16:43 ` Ammar Faizi [this message]
2022-10-19 16:43 ` [PATCH ncns v1 2/2] chnet: Add thread index specifier for chromium thread Ammar Faizi
2022-10-19 22:38   ` Alviro Iskandar Setiawan
2022-10-19 22:36 ` [PATCH ncns v1 0/2] Small optimization and improve debugging experience Alviro Iskandar Setiawan
2022-10-19 22:53   ` Ammar Faizi
2022-10-19 22:56     ` Alviro Iskandar Setiawan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox