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(); } } }
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(); } } }
public void Reset() { AsyncType = EAsyncType.Normal; PostAction = null; Awaiter = null; ContinueThread = null; AsyncTarget = null; Tag = null; ExceptionInfo = null; CallStackTrace = null; }
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)); } }