diff options
-rw-r--r-- | global-functions | 17 |
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; } |