public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* RFA [PATCH] * lock-and-run.sh: Check for process existence rather than timeout.
@ 2019-10-14 21:38 Jason Merrill
  2019-10-19  4:47 ` Alexandre Oliva
  0 siblings, 1 reply; 5+ messages in thread
From: Jason Merrill @ 2019-10-14 21:38 UTC (permalink / raw)
  To: gcc-patches; +Cc: oliva

Matthias Klose noted that on less powerful targets, a link might take more
than 5 minutes; he mentions a figure of 3 hours for an LTO link.  So this
patch changes the timeout to a check for whether the locking process still
exists.

Alex, you had a lot of helpful comments when I first wrote this, any thoughts
on this revision?

---
 gcc/lock-and-run.sh | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/gcc/lock-and-run.sh b/gcc/lock-and-run.sh
index 3a6a84c253a..404350b89a4 100644
--- a/gcc/lock-and-run.sh
+++ b/gcc/lock-and-run.sh
@@ -5,29 +5,28 @@ lockdir="$1" prog="$2"; shift 2 || exit 1
 
 # Remember when we started trying to acquire the lock.
 count=0
-touch lock-stamp.$$
 
-trap 'rm -r "$lockdir" lock-stamp.$$' 0
+trap 'rm -rf "$lockdir"' 0
 
 until mkdir "$lockdir" 2>/dev/null; do
     # Say something periodically so the user knows what's up.
     if [ `expr $count % 30` = 0 ]; then
-	# Reset if the lock has been renewed.
-	if [ -n "`find \"$lockdir\" -newer lock-stamp.$$`" ]; then
-	    touch lock-stamp.$$
-	    count=1
-	# Steal the lock after 5 minutes.
-	elif [ $count = 300 ]; then
-	    echo removing stale $lockdir >&2
-	    rm -r "$lockdir"
+	# Check for stale lock.
+	pid="`(cd $lockdir; echo *)`"
+	if ps "$pid" >/dev/null; then
+	    echo PID $$ waiting $count sec to acquire $lockdir from PID $pid>&2
+	    found=$pid
 	else
-	    echo waiting to acquire $lockdir >&2
+	    echo PID $pid is dead, removing stale $lockdir >&2
+	    rm -r "$lockdir"
 	fi
     fi
     sleep 1
     count=`expr $count + 1`
 done
 
+touch $lockdir/$$
+echo PID $$ acquired $lockdir after $count seconds >&2
 echo $prog "$@"
 $prog "$@"
 

base-commit: aa45db50a034b266c338b55dee1b412178ea84a7
-- 
2.18.1

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-10-22  3:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-14 21:38 RFA [PATCH] * lock-and-run.sh: Check for process existence rather than timeout Jason Merrill
2019-10-19  4:47 ` Alexandre Oliva
     [not found]   ` <CADzB+2mRrBrZTtvjUHxpvfGumwjjjJAcGooq1gRKaAvkanDegA@mail.gmail.com>
2019-10-21 17:28     ` Jason Merrill
2019-10-21 23:32     ` Alexandre Oliva
2019-10-22  3:49       ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).