Exemplo n.º 1
0
        /// <summary>
        /// Release pip's resources after worker is done with the task
        /// </summary>
        public void ReleaseResources(RunnablePip runnablePip)
        {
            Contract.Assert(runnablePip.AcquiredResourceWorker == this);

            runnablePip.AcquiredResourceWorker = null;

            if (runnablePip.Step == PipExecutionStep.CacheLookup)
            {
                Interlocked.Decrement(ref m_acquiredCacheLookupSlots);
                OnWorkerResourcesChanged(WorkerResource.AvailableCacheLookupSlots, increased: true);
                runnablePip.SetWorker(null);
                return;
            }

            runnablePip.AcquiredResourceWorker = null;
            var processRunnablePip = runnablePip as ProcessRunnablePip;

            if (processRunnablePip != null)
            {
                Contract.Assert(processRunnablePip.Resources.HasValue);

                Interlocked.Add(ref m_acquiredProcessSlots, -processRunnablePip.Process.Weight);

                var resources = processRunnablePip.Resources.Value;
                m_workerSemaphores.ReleaseResources(resources);

                OnWorkerResourcesChanged(WorkerResource.AvailableProcessSlots, increased: true);
            }

            if (runnablePip.PipType == PipType.Ipc)
            {
                Interlocked.Decrement(ref m_acquiredIpcSlots);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Release pip's resources after worker is done with the task
        /// </summary>
        public void ReleaseResources(RunnablePip runnablePip)
        {
            Contract.Assert(runnablePip.AcquiredResourceWorker == this);

            runnablePip.AcquiredResourceWorker = null;

            var processRunnablePip = runnablePip as ProcessRunnablePip;

            if (processRunnablePip != null)
            {
                if (runnablePip.Step == PipExecutionStep.CacheLookup)
                {
                    Interlocked.Decrement(ref m_acquiredCacheLookupSlots);
                    OnWorkerResourcesChanged(WorkerResource.AvailableCacheLookupSlots, increased: true);
                    runnablePip.SetWorker(null);
                }
                else
                {
                    Contract.Assert(processRunnablePip.Resources.HasValue);

                    Interlocked.Add(ref m_acquiredProcessSlots, -processRunnablePip.Weight);

                    var resources = processRunnablePip.Resources.Value;
                    m_workerSemaphores.ReleaseResources(resources);

                    OnWorkerResourcesChanged(WorkerResource.AvailableProcessSlots, increased: true);
                }
            }

            if (runnablePip.PipType == PipType.Ipc)
            {
                Interlocked.Decrement(ref m_acquiredIpcSlots);
            }

            if (AcquiredSlots == 0 && Status == WorkerNodeStatus.Stopping)
            {
                DrainCompletion.TrySetResult(true);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Release pip's resources after worker is done with the task
        /// </summary>
        public void ReleaseResources(RunnablePip runnablePip, PipExecutionStep nextStep)
        {
            Contract.Assert(runnablePip.AcquiredResourceWorker == this);

            var  stepCompleted       = runnablePip.Step;
            bool isCancelledOrFailed = nextStep == PipExecutionStep.ChooseWorkerCpu || nextStep == PipExecutionStep.HandleResult;

            var processRunnablePip = runnablePip as ProcessRunnablePip;

            if (processRunnablePip != null)
            {
                switch (stepCompleted)
                {
                case PipExecutionStep.CacheLookup:
                {
                    Interlocked.Decrement(ref m_acquiredCacheLookupSlots);
                    OnWorkerResourcesChanged(WorkerResource.AvailableCacheLookupSlots, increased: true);
                    runnablePip.SetWorker(null);
                    runnablePip.AcquiredResourceWorker = null;
                    break;
                }

                case PipExecutionStep.MaterializeInputs:
                {
                    Interlocked.Decrement(ref m_acquiredMaterializeInputSlots);
                    OnWorkerResourcesChanged(WorkerResource.AvailableMaterializeInputSlots, increased: true);
                    if (isCancelledOrFailed)
                    {
                        releaseExecuteProcessSlots();
                        releasePostProcessSlots();
                    }

                    break;
                }

                case PipExecutionStep.ExecuteProcess:
                {
                    releaseExecuteProcessSlots();
                    if (isCancelledOrFailed)
                    {
                        releasePostProcessSlots();
                    }

                    break;
                }

                case PipExecutionStep.PostProcess:
                {
                    releasePostProcessSlots();
                    break;
                }
                }
            }

            if (runnablePip.PipType == PipType.Ipc)
            {
                if (stepCompleted == PipExecutionStep.ExecuteNonProcessPip || isCancelledOrFailed)
                {
                    Interlocked.Decrement(ref m_acquiredLightSlots);
                    runnablePip.SetWorker(null);
                    runnablePip.AcquiredResourceWorker = null;
                }
            }

            if (AcquiredSlots == 0 && Status == WorkerNodeStatus.Stopping)
            {
                DrainCompletion.TrySetResult(true);
            }

            void releaseExecuteProcessSlots()
            {
                Contract.Assert(processRunnablePip.Resources.HasValue);

                if (processRunnablePip.Process.IsLight)
                {
                    Interlocked.Decrement(ref m_acquiredLightSlots);
                }
                else
                {
                    Interlocked.Add(ref m_acquiredProcessSlots, -processRunnablePip.Weight);
                    OnWorkerResourcesChanged(WorkerResource.AvailableProcessSlots, increased: true);
                }

                var resources = processRunnablePip.Resources.Value;

                m_workerSemaphores.ReleaseResources(resources);
            }

            void releasePostProcessSlots()
            {
                Interlocked.Decrement(ref m_acquiredPostProcessSlots);
                runnablePip.SetWorker(null);
                runnablePip.AcquiredResourceWorker = null;
            }
        }