Exemple #1
0
        void OnDestroy()
        {
            _asyncDisruptor.Shutdown();
            _asyncDisruptor = null;
            _asyncThreadPoolScheduler.Dispose();
            _asyncThreadPoolScheduler = null;

            if (_asyncIoDisruptor != null)
            {
                _asyncIoDisruptor.Shutdown();
            }
            if (_asyncIoThreadPoolScheduler != null)
            {
                _asyncIoThreadPoolScheduler.Dispose();
            }
        }
Exemple #2
0
        void Awake()
        {
            _jobPoolSize = Mathf.ClosestPowerOfTwo(_jobPoolSize);
            _jobPool     = new Queue <Job>(_jobPoolSize);
            var taskPoolSize = _jobPoolSize * 3;

            _taskPool = new Queue <JobTask>(taskPoolSize);

            Action <Job> taskCompleted = OnTaskCompleted;

            for (int i = 0; i < _jobPoolSize; i++)
            {
                _jobPool.Enqueue(new Job(_taskPool, taskCompleted));
            }
            for (int i = 0; i < taskPoolSize; i++)
            {
                _taskPool.Enqueue(new JobTask());
            }

            _unityTasks = new HeapPriorityQueue <JobTask>(_jobPoolSize);
            _queuedJobs = new List <Job>(_jobPoolSize);

            var numAsyncThreads = 1;
            //var numAsyncThreads = Mathf.Clamp(SystemInfo.processorCount / 2, 1, 2);
            bool singleDisruptor = numAsyncThreads == 1;

            if (singleDisruptor)
            {
                _asyncThreadPoolScheduler = new FixedThreadPoolScheduler(numAsyncThreads, isBackground: false);
                _asyncDisruptor           = new Disruptor <DisruptorTask>(
                    () => new DisruptorTask(),
                    new MultiThreadedClaimStrategy(_jobPoolSize),
                    new BlockingWaitStrategy(),
                    _asyncThreadPoolScheduler);
                _asyncDisruptor.HandleEventsWith(new DisruptorJobHandler());
                _asyncDisruptor.Start();

                _asyncIoDisruptor = _asyncDisruptor;

                Debug.Log("JobManager || Using single disruptor, with " + numAsyncThreads + " async threads, " + 0 + " io threads");
            }
            else
            {
                _asyncThreadPoolScheduler = new FixedThreadPoolScheduler(numAsyncThreads, isBackground: false);
                _asyncDisruptor           = new Disruptor <DisruptorTask>(
                    () => new DisruptorTask(),
                    new MultiThreadedClaimStrategy(_jobPoolSize),
                    new BlockingWaitStrategy(),
                    _asyncThreadPoolScheduler);
                _asyncDisruptor.HandleEventsWith(new DisruptorJobHandler());
                _asyncDisruptor.Start();

                var numIoThreads = 1;
                _asyncIoThreadPoolScheduler = new FixedThreadPoolScheduler(numIoThreads, isBackground: false);
                _asyncIoDisruptor           = new Disruptor <DisruptorTask>(
                    () => new DisruptorTask(),
                    new MultiThreadedClaimStrategy(_jobPoolSize),
                    new BlockingWaitStrategy(),
                    _asyncThreadPoolScheduler);
                _asyncIoDisruptor.HandleEventsWith(new DisruptorJobHandler());
                _asyncIoDisruptor.Start();

                Debug.Log("JobManager || Using multiple disruptors, with " + numAsyncThreads + " async threads, " + numIoThreads + " io threads");
            }
        }