Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH v2 3/6] [gdb/testsuite] Simplify lock_file_acquire
Date: Tue, 29 Sep 2026 13:09:18 +0200	[thread overview]
Message-ID: <20260929110921.1910094-3-tdevries@suse.de> (raw)
In-Reply-To: <20260929110921.1910094-1-tdevries@suse.de>

Currently the entire functionality of lock_file_acquire is contained in a
loop, which makes control flow harder to follow, especially so given that the
loop also contains exception handling.

Instead, limit the scope of the loop to the part that actually needs
repeating: getting a valid file handle:
...
    while {![info exists fh]} {
	try {
	    set fh [open $lockfile {WRONLY CREAT EXCL}]
	} on error {} {
	    # Ignore and try again.
	    after 10
	}
    }
...

I also liked this version:
...
    while {true} {
	try {
	    set fh [open $lockfile {WRONLY CREAT EXCL}]
	    break
	} on error {} {
	    # Ignore and try again.
	    after 10
	    continue
	}
    }
...
but ended up choosing for the first because the loop condition states the goal
of the loop.
---
 gdb/testsuite/lib/gdb-utils.exp | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/gdb/testsuite/lib/gdb-utils.exp b/gdb/testsuite/lib/gdb-utils.exp
index 56d8e80f152..854496e9bb1 100644
--- a/gdb/testsuite/lib/gdb-utils.exp
+++ b/gdb/testsuite/lib/gdb-utils.exp
@@ -185,22 +185,24 @@ proc version_compare { l1 op l2 } {
 
 proc lock_file_acquire {lockfile} {
     verbose -log "acquiring lock file: $::subdir/${::gdb_test_file_name}.exp"
-    while {true} {
+
+    while {![info exists fh]} {
 	try {
-	    open $lockfile {WRONLY CREAT EXCL}
-	} on ok {fh} {
-	    set msg "locked by $::subdir/${::gdb_test_file_name}.exp"
-	    verbose -log "lock file: $msg"
-	    # For debugging, put info in the lockfile about who owns
-	    # it.
-	    puts $fh $msg
-	    flush $fh
-	    return [list $fh $lockfile]
+	    set fh [open $lockfile {WRONLY CREAT EXCL}]
 	} on error {} {
 	    # Ignore and try again.
+	    after 10
 	}
-	after 10
     }
+
+    set msg "locked by $::subdir/${::gdb_test_file_name}.exp"
+    verbose -log "lock file: $msg"
+
+    # For debugging, put info in the lockfile about who owns
+    # it.
+    puts $fh $msg
+    flush $fh
+    return [list $fh $lockfile]
 }
 
 # Release a lock file.
-- 
2.51.0


  parent reply	other threads:[~2026-09-29 11:11 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-29 11:09 [PATCH v2 1/6] [gdb/testsuite] Add gdb.testsuite/lock.exp Tom de Vries
2026-09-29 11:09 ` [PATCH v2 2/6] [gdb/testsuite] Improve variable names in lock_file_{acquire, release} Tom de Vries
2026-09-29 11:09 ` Tom de Vries [this message]
2026-09-29 11:09 ` [PATCH v2 4/6] [gdb/testsuite] Only retry on EEXIST in lock_file_acquire Tom de Vries
2026-09-29 11:09 ` [PATCH v2 5/6] [gdb/testsuite] Extend gdb.testsuite/lock.exp Tom de Vries
2026-09-29 11:09 ` [PATCH v2 6/6] [gdb/testsuite] Extend gdb.testsuite/lock.exp a bit more Tom de Vries

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 \
    --in-reply-to=20260929110921.1910094-3-tdevries@suse.de \
    --to=tdevries@suse.de \
    --cc=gdb-patches@sourceware.org \
    /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