diff options
author | Christian Hesse <mail@eworm.de> | 2021-06-30 21:27:39 +0200 |
---|---|---|
committer | Christian Hesse <mail@eworm.de> | 2021-06-30 21:28:27 +0200 |
commit | 7de3457f449bcb37f39a12ea81e3c73cfb14e7ba (patch) | |
tree | eb2bf44e178eb656438d2e3c35e5178f014dfc3e | |
parent | 5d30886e597aa3ea0b5bc4ccbf7f62713df0de3d (diff) |
global-functions: $ScriptLock: allow to wait for lock
-rw-r--r-- | global-functions | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/global-functions b/global-functions index 6c11258..a19e44b 100644 --- a/global-functions +++ b/global-functions @@ -906,6 +906,7 @@ :set ScriptLock do={ :local Script [ :tostr $1 ]; :local DoReturn $2; + :local DoWait $3; :global GetRandomNumber; :global IfThenElse; @@ -949,6 +950,11 @@ :local MyTicket [ $GetRandomNumber ]; :set ($ScriptLockOrder->$Script) [ $AddTicket ($ScriptLockOrder->$Script) $MyTicket ]; + :while ($DoWait = true && (($ScriptLockOrder->$Script->0) != $MyTicket || [ :len ($ScriptLockOrder->$Script) ] < $JobCount)) do={ + :delay 100ms; + :set JobCount [ :len [ / system script job find where script=$Script ] ]; + } + :if ([ :len ($ScriptLockOrder->$Script) ] = $JobCount && ($ScriptLockOrder->$Script->0) = $MyTicket) do={ :set ($ScriptLockOrder->$Script) [ $RemoveTicket ($ScriptLockOrder->$Script) $MyTicket ]; :return false; |