aboutsummaryrefslogtreecommitdiffstats
path: root/global-functions
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2021-08-30 20:44:02 +0200
committerGravatar Christian Hesse <mail@eworm.de>2021-08-31 21:40:42 +0200
commitd356d6f57c3cd35b078811110a79802f49ed9529 (patch)
treecc4a7389d6e5194108e6a0261671c7d75f187740 /global-functions
parent6b04fff3eb2214eafa8dab01bfef672508d2440e (diff)
global-functions: $ScriptLock: do not store but calculate job count
This should mitigate some more race conditions.
Diffstat (limited to 'global-functions')
-rw-r--r--global-functions17
1 files changed, 10 insertions, 7 deletions
diff --git a/global-functions b/global-functions
index bbea143..f2b8ea1 100644
--- a/global-functions
+++ b/global-functions
@@ -925,6 +925,12 @@
:set ScriptLockOrder [ :toarray "" ];
}
+ :local JobCount do={
+ :local Script [ :tostr $1 ];
+
+ :return [ :len [ / system script job find where script=$Script ] ];
+ }
+
:local AddTicket do={
:local Script [ :tostr $1 ];
:local Add [ :tostr $2 ];
@@ -963,13 +969,11 @@
$LogPrintExit2 error $0 ("A script named '" . $Script . "' does not exist!") true;
}
- :local JobCount [ :len [ / system script job find where script=$Script ] ];
-
- :if ($JobCount = 0) do={
+ :if ([ $JobCount $Script ] = 0) do={
$LogPrintExit2 error $0 ("No script '" . $Script . "' is running!") true;
}
- :if ([ :len ($ScriptLockOrder->$Script) ] >= $JobCount) do={
+ :if ([ :len ($ScriptLockOrder->$Script) ] >= [ $JobCount $Script ]) do={
$LogPrintExit2 error $0 ("More tickets than running scripts '" . $Script . "', resetting!") false;
:set ($ScriptLockOrder->$Script);
/ system script job remove [ find where script=$Script ];
@@ -979,13 +983,12 @@
$AddTicket $Script $MyTicket;
:local WaitCount 0;
- :while ($WaitMax > $WaitCount && (($ScriptLockOrder->$Script->0) != $MyTicket || [ :len ($ScriptLockOrder->$Script) ] < $JobCount)) do={
+ :while ($WaitMax > $WaitCount && (($ScriptLockOrder->$Script->0) != $MyTicket || [ :len ($ScriptLockOrder->$Script) ] < [ $JobCount $Script ])) do={
:delay 100ms;
:set WaitCount ($WaitCount + 1);
- :set JobCount [ :len [ / system script job find where script=$Script ] ];
}
- :if ([ :len ($ScriptLockOrder->$Script) ] = $JobCount && ($ScriptLockOrder->$Script->0) = $MyTicket) do={
+ :if (($ScriptLockOrder->$Script->0) = $MyTicket && [ :len ($ScriptLockOrder->$Script) ] = [ $JobCount $Script ]) do={
$RemoveTicket $Script $MyTicket;
:return false;
}