Exemplo n.º 1
0
 internal void ReturnToPool()
 {
     Reset();
     //careful, this reasoning is convoluted:
     //I need to be sure that the ContinuatorEnumerator is invalid in the moment is back to the pool
     //(it would be the same to shift the reasoning when it's take from the pool, but this is even safer)
     //At this point in time, Svelto.Tasks may still holding the continuation enumerator to check if the
     //task is done. But how can I know how long a runner is going to hold the continuation enumerator for?
     //therefore the "signature" will invalidate stale holders and therefore it's safe here to set
     //_completed to false
     
     ContinuationPool.PushBack(this); //and return to the pool
 }
        internal ContinuationEnumerator Run <TRunner>(TRunner runner, ref TTask task)
            where TRunner : class, IRunner <LeanSveltoTask <TTask> >
        {
            _sveltoTask = new SveltoTaskWrapper <TTask, IRunner <LeanSveltoTask <TTask> > >(ref task, runner);
#if DEBUG && !PROFILE_SVELTO
            DBC.Tasks.Check.Require(IS_TASK_STRUCT == true || task != null,
                                    "A valid enumerator is required to enable a LeanSveltTask ".FastConcat(ToString()));

            DBC.Tasks.Check.Require(runner != null, "SetScheduler function has never been called");
#endif

            _continuationEnumerator             = new ContinuationEnumerator(ContinuationPool.RetrieveFromPool());
            _threadSafeSveltoTaskStates.started = true;

            runner.StartCoroutine(this);

            return(_continuationEnumerator);
        }
        internal ContinuationEnumerator Start <TRunner>(TRunner runner, ref TTask task, bool immediate) where TRunner : class, IInternalRunner <LeanSveltoTask <TTask> >
        {
#if DEBUG && !PROFILER
            DBC.Tasks.Check.Require(IS_TASK_STRUCT == true || task != null,
                                    "A valid enumerator is required to enable a LeanSveltTask ".FastConcat(ToString()));

            DBC.Tasks.Check.Require(runner != null, "SetScheduler function has never been called");
#endif

#if GENERATE_NAME
            _name = task.ToString();
#endif
            _continuationEnumerator             = ContinuationPool.RetrieveFromPool();
            _sveltoTask                         = new SveltoTaskWrapper <TTask, IInternalRunner <LeanSveltoTask <TTask> > >(ref task, runner);
            _threadSafeSveltoTaskStates.started = true;

            runner.StartCoroutine(ref this, immediate);

            return(_continuationEnumerator);
        }
Exemplo n.º 4
0
        internal void Completed()
        {
            ContinuationPool.PushBack(this);

            ThreadUtility.VolatileWrite(ref _completed, true);
        }