diff options
-rw-r--r-- | global-functions | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/global-functions b/global-functions index d11f8e2..6af914f 100644 --- a/global-functions +++ b/global-functions @@ -918,17 +918,34 @@ } :local AddTicket do={ - :return ($1, $2); + :local Script [ :tostr $1 ]; + :local Add [ :tostr $2 ]; + + :global ScriptLockOrder; + + :local Ok false; + :while ($Ok = false) do={ + :set ($ScriptLockOrder->$Script) (($ScriptLockOrder->$Script), $Add); + :delay 10ms; + :foreach Ticket in=($ScriptLockOrder->$Script) do={ + :if ($Ticket = $Add) do={ :set Ok true; } + } + } } :local RemoveTicket do={ - :local Return [ :toarray "" ]; - :foreach Ticket in=$1 do={ - :if ($Ticket != $2) do={ - :set Return ($Return, $Ticket); + :local Script [ :tostr $1 ]; + :local Remove [ :tostr $2 ]; + + :global ScriptLockOrder; + + :local New [ :toarray "" ]; + :foreach Ticket in=($ScriptLockOrder->$Script) do={ + :if ($Ticket != $Remove) do={ + :set New ($New, $Ticket); } } - :return $Return; + :set ($ScriptLockOrder->$Script) $New; } :if ([ :len [ / system script find where name=$Script ] ] = 0) do={ @@ -945,10 +962,10 @@ $LogPrintExit2 error $0 ("More tickets than running scripts '" . $Script . "', resetting!") false; :set ($ScriptLockOrder->$Script); / system script job remove [ find where script=$Script ]; - } + } :local MyTicket [ $GetRandom20CharHex ]; - :set ($ScriptLockOrder->$Script) [ $AddTicket ($ScriptLockOrder->$Script) $MyTicket ]; + $AddTicket $Script $MyTicket; :local WaitCount 0; :while ($WaitMax > $WaitCount && (($ScriptLockOrder->$Script->0) != $MyTicket || [ :len ($ScriptLockOrder->$Script) ] < $JobCount)) do={ @@ -958,11 +975,11 @@ } :if ([ :len ($ScriptLockOrder->$Script) ] = $JobCount && ($ScriptLockOrder->$Script->0) = $MyTicket) do={ - :set ($ScriptLockOrder->$Script) [ $RemoveTicket ($ScriptLockOrder->$Script) $MyTicket ]; + $RemoveTicket $Script $MyTicket; :return false; } - :set ($ScriptLockOrder->$Script) [ $RemoveTicket ($ScriptLockOrder->$Script) $MyTicket ]; + $RemoveTicket $Script $MyTicket; $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; |