From patchwork Fri Jul 28 10:59:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 73321 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A3915385AFA9 for ; Fri, 28 Jul 2023 11:01:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A3915385AFA9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1690542063; bh=pEjGWKUELoVOj3sqtqrtMdSlgnLqLU+GxoDzESM/zdk=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=FXar8FgPdA7aa12FpClx9qQQICIaLEIApMIcjY/pCXkQ4r0uz5MwyPRpxsCOl85bd vudqJqJXSXyI8WZaFqVy1yo0zMFgdde9YXfzssbzJqk/VUEb8wMFGJuMjT5GNG1vtB ybshtPlYtriEG/+YoAKsjeEsJJ7RPwLLDCeqpW88= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 136113858D33 for ; Fri, 28 Jul 2023 11:00:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 136113858D33 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 022D621910 for ; Fri, 28 Jul 2023 11:00:02 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id DC0CF133F7 for ; Fri, 28 Jul 2023 11:00:01 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id Zx2AMrGfw2QoOQAAMHmgww (envelope-from ) for ; Fri, 28 Jul 2023 11:00:01 +0000 To: gdb-patches@sourceware.org Subject: [PATCH 1/2] [gdb] Rename variable main_thread to main_thread_id Date: Fri, 28 Jul 2023 12:59:44 +0200 Message-Id: <20230728105945.13909-1-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom de Vries via Gdb-patches From: Tom de Vries Reply-To: Tom de Vries Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" I noticed that the variable main_thread: ... /* The main thread. */ static std::thread::id main_thread; ... has a confusing name and corresponding comment, because it doesn't contain the main thread, but rather the main thread's std::thread::id. Fix this by renaming to main_thread_id. Tested on x86_64-linux. --- gdb/run-on-main-thread.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) base-commit: 29c108c9610640439daa5244a573348b7c47d994 diff --git a/gdb/run-on-main-thread.c b/gdb/run-on-main-thread.c index c7d9de0afc8..91d25dae28f 100644 --- a/gdb/run-on-main-thread.c +++ b/gdb/run-on-main-thread.c @@ -39,9 +39,9 @@ static std::vector> runnables; static std::mutex runnable_mutex; -/* The main thread. */ +/* The main thread's thread id. */ -static std::thread::id main_thread; +static std::thread::id main_thread_id; #endif @@ -100,7 +100,7 @@ bool is_main_thread () { #if CXX_STD_THREAD - return std::this_thread::get_id () == main_thread; + return std::this_thread::get_id () == main_thread_id; #else return true; #endif @@ -111,7 +111,7 @@ void _initialize_run_on_main_thread () { #if CXX_STD_THREAD - main_thread = std::this_thread::get_id (); + main_thread_id = std::this_thread::get_id (); #endif runnable_event = make_serial_event (); add_file_handler (serial_event_fd (runnable_event), run_events, nullptr, From patchwork Fri Jul 28 10:59:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 73320 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D8E6038560AA for ; Fri, 28 Jul 2023 11:00:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D8E6038560AA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1690542027; bh=p8SXWsjnbCHiDI3Yw4yZ5/L5USt6hOxXNGMh9NXmnqg=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=QZeKrbXSMVf6C+z6S6A7jDGvfXSmmVlXTyH9CkT1oZFunI9EnCKgMfXbZxeDZYpWd MyUvzi/FN0cgvQc4UDErItcfVPJ9wkdnUc3J9He9l/77WlEV7LxisluqreiY8LycQj ZnON90XudcdvaZfoJLVvfchvQooeAeKmS7rEjhPk= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id 2326D3858CDA for ; Fri, 28 Jul 2023 11:00:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2326D3858CDA Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 1189A219C9 for ; Fri, 28 Jul 2023 11:00:02 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id F1C89139BD for ; Fri, 28 Jul 2023 11:00:01 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id UE0FOrGfw2QoOQAAMHmgww (envelope-from ) for ; Fri, 28 Jul 2023 11:00:01 +0000 To: gdb-patches@sourceware.org Subject: [PATCH 2/2] [gdb] Initialize main_thread_id earlier Date: Fri, 28 Jul 2023 12:59:45 +0200 Message-Id: <20230728105945.13909-2-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230728105945.13909-1-tdevries@suse.de> References: <20230728105945.13909-1-tdevries@suse.de> MIME-Version: 1.0 X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom de Vries via Gdb-patches From: Tom de Vries Reply-To: Tom de Vries Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" I wrote a patch using is_main_thread (), and found it returning false in the main thread due to main_thread_id not being initialized yet. Initialization currently takes place in _initialize_run_on_main_thread, but that's too late for earlier uses. Fix this by also initializing on first use. Tested on x86_64-linux. --- gdb/run-on-main-thread.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/gdb/run-on-main-thread.c b/gdb/run-on-main-thread.c index 91d25dae28f..bee5885d9a6 100644 --- a/gdb/run-on-main-thread.c +++ b/gdb/run-on-main-thread.c @@ -94,12 +94,27 @@ run_on_main_thread (std::function &&func) serial_event_set (runnable_event); } +#if CXX_STD_THREAD +static void +initialize_main_thread_id (void) +{ + static bool initialized = false; + + if (initialized) + return; + initialized = true; + + main_thread_id = std::this_thread::get_id (); +} +#endif + /* See run-on-main-thread.h. */ bool is_main_thread () { #if CXX_STD_THREAD + initialize_main_thread_id (); return std::this_thread::get_id () == main_thread_id; #else return true; @@ -111,7 +126,7 @@ void _initialize_run_on_main_thread () { #if CXX_STD_THREAD - main_thread_id = std::this_thread::get_id (); + initialize_main_thread_id (); #endif runnable_event = make_serial_event (); add_file_handler (serial_event_fd (runnable_event), run_events, nullptr,