Esempio n. 1
0
        public void RunOn <T>(FAsyncPostEvent <T> evt, EAsyncTarget target = EAsyncTarget.AsyncIO)
        {
            if (ContextThreadManager.ImmidiateMode)
            {
                evt();
                return;
            }

            ContextThread ctx = GetContext(target);
            FPostEvent    ue  = () =>
            {
                return(evt());
            };
            var eh = mRunOnPEAllocator.QueryObjectSync();

            eh.PostAction     = ue;
            eh.ContinueThread = null;
            eh.AsyncType      = EAsyncType.ParallelTasks;
            if (ctx != null)
            {
                lock (ctx.PriorityEvents)
                {
                    ctx.PriorityEvents.Enqueue(eh);
                }
            }
            else
            {
                lock (TPoolEvents)
                {
                    TPoolEvents.Enqueue(eh);
                    mTPoolTrigger.Set();
                }
            }
        }
Esempio n. 2
0
        public void RunOn(FPostEvent evt, EAsyncTarget target = EAsyncTarget.AsyncIO)
        {
            ContextThread ctx = GetContext(target);

            var eh = mRunOnPEAllocator.QueryObjectSync();

            eh.PostAction     = evt;
            eh.ContinueThread = null;
            eh.AsyncType      = EAsyncType.ParallelTasks;
            if (ctx != null)
            {
                lock (ctx.PriorityEvents)
                {
                    ctx.PriorityEvents.Enqueue(eh);
                }
            }
            else
            {
                lock (TPoolEvents)
                {
                    TPoolEvents.Enqueue(eh);
                    mTPoolTrigger.Set();
                }
            }
        }
Esempio n. 3
0
        public ContextThread GetContext(EAsyncTarget target)
        {
            ContextThread ctx = null;

            switch (target)
            {
            case EAsyncTarget.AsyncIO:
                ctx = ContextAsyncIO;
                break;

            case EAsyncTarget.Physics:
                ctx = ContextPhysics;
                break;

            case EAsyncTarget.Logic:
                ctx = ContextLogic;
                break;

            case EAsyncTarget.Render:
                ctx = ContextRHI;
                break;

            case EAsyncTarget.Main:
                ctx = ContextMain;
                break;

            case EAsyncTarget.Editor:
                ctx = ContextEditor;
                break;

            case EAsyncTarget.AsyncEditor:
                ctx = ContextAsyncEditor;
                break;

            case EAsyncTarget.AsyncEditorSlow:
                ctx = ContextAsyncEditorSlow;
                break;

            case EAsyncTarget.WaitCreated:
                ctx = ContextWaitCreated;
                break;

            case EAsyncTarget.TPools:
                break;
            }
            return(ctx);
        }
Esempio n. 4
0
        public bool IsThread(EAsyncTarget target)
        {
            var ctx = ContextThread.CurrentContext;

            switch (target)
            {
            case EAsyncTarget.AsyncIO:
                return(ctx == ContextAsyncIO);

            case EAsyncTarget.Physics:
                return(ctx == ContextPhysics);

            case EAsyncTarget.Logic:
                return(ctx == ContextLogic);

            case EAsyncTarget.Render:
                return(ctx == ContextRHI);

            case EAsyncTarget.Main:
                return(ctx == ContextMain);

            case EAsyncTarget.Editor:
                return(ctx == ContextEditor);

            case EAsyncTarget.AsyncEditor:
                return(ctx == ContextAsyncEditor);

            case EAsyncTarget.AsyncEditorSlow:
                return(ctx == ContextAsyncEditorSlow);

            case EAsyncTarget.WaitCreated:
                return(ctx == ContextWaitCreated);

            case EAsyncTarget.TPools:
                break;
            }
            return(false);
        }
Esempio n. 5
0
        public async System.Threading.Tasks.Task <T> Post <T>(FPostEventReturn <T> evt, EAsyncTarget target = EAsyncTarget.AsyncIO)
        {
            var           eh  = new PostEvent();
            ContextThread ctx = GetContext(target);

            eh.AsyncTarget    = ctx;
            eh.ContinueThread = ContextThread.CurrentContext;
            if (eh.ContinueThread == this.ContextRHI)
            {
                switch (eh.ContinueThread.TickFlag)
                {
                case 1:
                    eh.ContinueThread = this.ContextMain;
                    break;

                case 2:
                    eh.ContinueThread = this.ContextRHI;
                    break;

                case 3:
                    eh.ContinueThread = this.ContextEditor;
                    break;
                }
            }
            FPostEvent ue = () =>
            {
                try
                {
                    var result = evt();
                    return(result);
                }
                catch (Exception ex)
                {
                    Profiler.Log.WriteException(ex);
                    return(default(T));
                }
            };

            eh.PostAction = ue;
            var    source = new System.Threading.Tasks.TaskCompletionSource <object>();
            object ret    = await source.Task.AwaitPost(eh);

            try
            {
                return((T)ret);
            }
            catch
            {
                return(default(T));
            }
        }