[v2,3/6,gdb/testsuite] Simplify lock_file_acquire
Checks
| Context |
Check |
Description |
| linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_gdb_build--master-arm |
success
|
Build passed
|
Commit Message
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(-)
@@ -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.