aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2021-07-01 10:26:16 +0200
committerGravatar Christian Hesse <mail@eworm.de>2021-07-01 22:37:03 +0200
commit0b4c1861cf54a017bbe1e7cf6e0e91f4b63e9e73 (patch)
treefb0d543930ecda4a22d9ac6d9e8888a34e88d7ae
parent7de3457f449bcb37f39a12ea81e3c73cfb14e7ba (diff)
global-functions: $ScriptLock: use a limit on lock...
... to make sure it does not lock forever.
-rw-r--r--global-functions10
1 files changed, 6 insertions, 4 deletions
diff --git a/global-functions b/global-functions
index a19e44b..9c4a53e 100644
--- a/global-functions
+++ b/global-functions
@@ -906,7 +906,7 @@
:set ScriptLock do={
:local Script [ :tostr $1 ];
:local DoReturn $2;
- :local DoWait $3;
+ :local WaitMax ([ :tonum $3 ] * 10);
:global GetRandomNumber;
:global IfThenElse;
@@ -950,8 +950,10 @@
:local MyTicket [ $GetRandomNumber ];
:set ($ScriptLockOrder->$Script) [ $AddTicket ($ScriptLockOrder->$Script) $MyTicket ];
- :while ($DoWait = true && (($ScriptLockOrder->$Script->0) != $MyTicket || [ :len ($ScriptLockOrder->$Script) ] < $JobCount)) do={
+ :local WaitCount 0;
+ :while ($WaitMax > $WaitCount && (($ScriptLockOrder->$Script->0) != $MyTicket || [ :len ($ScriptLockOrder->$Script) ] < $JobCount)) do={
:delay 100ms;
+ :set WaitCount ($WaitCount + 1);
:set JobCount [ :len [ / system script job find where script=$Script ] ];
}
@@ -961,8 +963,8 @@
}
:set ($ScriptLockOrder->$Script) [ $RemoveTicket ($ScriptLockOrder->$Script) $MyTicket ];
- $LogPrintExit2 info $0 ("Script '" . $Script . "' started more than once... Aborting.") \
- [ $IfThenElse ($DoReturn = true) false true ];
+ $LogPrintExit2 info $0 ("Script '" . $Script . "' started more than once" . [ $IfThenElse ($WaitCount > 0) \
+ " and timed out waiting for lock" "" ] . "... Aborting.") [ $IfThenElse ($DoReturn = true) false true ];
:return true;
}