From c8827dab0a523aecaa3b91538e45566b8b2b0415 Mon Sep 17 00:00:00 2001 From: Alan Browning <8662070+omgpuppy@users.noreply.github.com> Date: Thu, 16 Jan 2020 11:57:10 -0800 Subject: [PATCH 1/2] Locally copy queue to avoid holding lock while Actions execute. --- UnityMainThreadDispatcher.cs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/UnityMainThreadDispatcher.cs b/UnityMainThreadDispatcher.cs index 3b40ca9..9101602 100644 --- a/UnityMainThreadDispatcher.cs +++ b/UnityMainThreadDispatcher.cs @@ -29,12 +29,18 @@ public class UnityMainThreadDispatcher : MonoBehaviour { private static readonly Queue _executionQueue = new Queue(); public void Update() { - lock(_executionQueue) { - while (_executionQueue.Count > 0) { - _executionQueue.Dequeue().Invoke(); - } - } - } + // Make local copy to avoid holding the lock while the actions execute. + Queue queueCopy; + lock (_executionQueue) + { + queueCopy = new Queue(_executionQueue); + _executionQueue.Clear(); + } + while (queueCopy.Count > 0) + { + queueCopy.Dequeue().Invoke(); + } + } /// /// Locks the queue and adds the IEnumerator to the queue From 7f3b51cc80f0f6f209368b4086fab8786a886052 Mon Sep 17 00:00:00 2001 From: Alan Browning <8662070+omgpuppy@users.noreply.github.com> Date: Fri, 17 Jan 2020 15:51:35 -0800 Subject: [PATCH 2/2] Ignore meta files --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c6bb293 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.meta