Beispiel #1
0
 public void For(int start, int end, int cycles, ForLoopDelegate loopBody, Action onEnd)
 {
     if (end - start < cycles)
     {
         Debug.LogError("end - start should be greater than cycles");
     }
     isFree = false;
     StartCoroutine(ForCo(start, end, cycles, loopBody, onEnd));
 }
Beispiel #2
0
        public static void For(int start, int end, int frames, ForLoopDelegate loopBody, Action onEnd)
        {
            var instance = GetInstance();

            if (end - start < frames)
            {
                Debug.LogError("end - start should be greater than frame count");
            }
            instance.StartCoroutine(instance.ForCo(start, end, frames, loopBody, onEnd));
        }
Beispiel #3
0
            private void Terminate()
            {
                // Finish thread by setting null loop body and signaling about available task
                LoopFunction = null;
                int workerThreadCount = this.workerThreads.Count;

                for (int i = 0; i < workerThreadCount; i++)
                {
                    this.workerThreads[i].Terminate();
                }
            }
Beispiel #4
0
        IEnumerator ForCo(int start, int end, int cycles, ForLoopDelegate loopBody, Action onEnd)
        {
            int i           = 0;
            int cycleLength = (end - start) / cycles;

            while (i != end)
            {
                loopBody(i);
                if (i % cycleLength == 0)
                {
                    yield return(null);
                }
                i++;
            }
            onEnd();
            yield break;
        }
Beispiel #5
0
            /// <summary>
            /// Runs the For loop.
            /// </summary>
            /// <param name="start">The start.</param>
            /// <param name="stop">The stop.</param>
            /// <param name="loopBody">The loop body.</param>
            public void DoFor(int start, int stop, ForLoopDelegate loopBody)
            {
                this.currentJobIndex = start - 1;
                this.stopIndex       = stop;
                this.LoopFunction    = loopBody;

                // Signal waiting task to all threads and mark them not idle.
                for (int i = 0; i < this.threadCount; i++)
                {
                    WorkerThread workerThread = workerThreads[i];
                    workerThread.ThreadIdle.Reset();
                    workerThread.TaskWaiting.Set();
                }

                // Wait until all threads become idle
                for (int i = 0; i < this.threadCount; i++)
                {
                    WorkerThread workerThread = workerThreads[i];
                    workerThread.ThreadIdle.WaitOne();
                }
            }