From fa712fc1d4a1f45f17df5a8979d17b2b8e5c9e2f Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 19 Feb 2021 16:09:36 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB=E5=88=86?= =?UTF-8?q?=E5=89=B2=E3=80=82Post?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IO/AltTask/AsyncMethodBuilderAttribute.cs | 12 ++++ .../AsyncMethodBuilderAttribute.cs.meta | 11 ++++ .../Runtime/UniGLTF/IO/AltTask/GenericTask.cs | 60 ------------------- .../Runtime/UniGLTF/IO/AltTask/TaskQueue.cs | 60 +++++++++++++++++++ .../UniGLTF/IO/AltTask/TaskQueue.cs.meta | 11 ++++ 5 files changed, 94 insertions(+), 60 deletions(-) create mode 100644 Assets/UniGLTF/Runtime/UniGLTF/IO/AltTask/AsyncMethodBuilderAttribute.cs create mode 100644 Assets/UniGLTF/Runtime/UniGLTF/IO/AltTask/AsyncMethodBuilderAttribute.cs.meta create mode 100644 Assets/UniGLTF/Runtime/UniGLTF/IO/AltTask/TaskQueue.cs create mode 100644 Assets/UniGLTF/Runtime/UniGLTF/IO/AltTask/TaskQueue.cs.meta diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/AltTask/AsyncMethodBuilderAttribute.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/AltTask/AsyncMethodBuilderAttribute.cs new file mode 100644 index 000000000..6228d159c --- /dev/null +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/AltTask/AsyncMethodBuilderAttribute.cs @@ -0,0 +1,12 @@ +namespace System.Runtime.CompilerServices +{ + public sealed class AsyncMethodBuilderAttribute : Attribute + { + public AsyncMethodBuilderAttribute(Type builderType) + { + BuilderType = builderType; + } + + public Type BuilderType { get; } + } +} diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/AltTask/AsyncMethodBuilderAttribute.cs.meta b/Assets/UniGLTF/Runtime/UniGLTF/IO/AltTask/AsyncMethodBuilderAttribute.cs.meta new file mode 100644 index 000000000..a12218427 --- /dev/null +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/AltTask/AsyncMethodBuilderAttribute.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 010eb0dc48af5e645af2ff8cb7f7d1d8 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/AltTask/GenericTask.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/AltTask/GenericTask.cs index 81edead6c..348764c03 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/AltTask/GenericTask.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/AltTask/GenericTask.cs @@ -4,18 +4,6 @@ using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; -namespace System.Runtime.CompilerServices -{ - public sealed class AsyncMethodBuilderAttribute : Attribute - { - public AsyncMethodBuilderAttribute(Type builderType) - { - BuilderType = builderType; - } - - public Type BuilderType { get; } - } -} namespace UniGLTF.AltTask { @@ -30,54 +18,6 @@ namespace UniGLTF.AltTask IAwaiter GetAwaiter(); } - public class TaskQueue : SynchronizationContext, IDisposable - { - [ThreadStatic] - static TaskQueue s_queue; - - public new static SynchronizationContext Current - { - get - { - if (s_queue == null) - { - return System.Threading.SynchronizationContext.Current; - } - else - { - return s_queue; - } - } - } - - Queue m_tasks = new Queue(); - - public static TaskQueue Create() - { - return new TaskQueue(); - } - - TaskQueue() - { - s_queue = this; - } - - public void Dispose() - { - s_queue = null; - } - - public bool ExecuteOneCallback() - { - if (m_tasks.Count == 0) - { - return false; - } - var task = m_tasks.Dequeue(); - task(); - return true; - } - } public struct ExplicitTaskMethodBuilder { diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/AltTask/TaskQueue.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/AltTask/TaskQueue.cs new file mode 100644 index 000000000..4446f232d --- /dev/null +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/AltTask/TaskQueue.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Threading; + +namespace UniGLTF.AltTask +{ + public class TaskQueue : SynchronizationContext, IDisposable + { + [ThreadStatic] + static TaskQueue s_queue; + + public new static SynchronizationContext Current + { + get + { + if (s_queue == null) + { + return System.Threading.SynchronizationContext.Current; + } + else + { + return s_queue; + } + } + } + + public override void Post(SendOrPostCallback d, object state) + { + m_tasks.Enqueue(() => d(state)); + } + + Queue m_tasks = new Queue(); + + public static TaskQueue Create() + { + return new TaskQueue(); + } + + TaskQueue() + { + s_queue = this; + } + + public void Dispose() + { + s_queue = null; + } + + public bool ExecuteOneCallback() + { + if (m_tasks.Count == 0) + { + return false; + } + var task = m_tasks.Dequeue(); + task(); + return true; + } + } +} diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/AltTask/TaskQueue.cs.meta b/Assets/UniGLTF/Runtime/UniGLTF/IO/AltTask/TaskQueue.cs.meta new file mode 100644 index 000000000..fef1e0f9d --- /dev/null +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/AltTask/TaskQueue.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6a65e00e71613c24e865e35173c30be0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: