コード例 #1
0
        private async Task <int> AnalyzeAffectedEntriesAsync(Stopwatch stopWatch)
        {
            IDependencyChainNode <PythonAnalyzerEntry> node;
            var remaining = 0;
            var ace       = new AsyncCountdownEvent(0);

            bool isCanceled;

            while ((node = await _walker.GetNextAsync(_analyzerCancellationToken)) != null)
            {
                lock (_syncObj) {
                    isCanceled = _isCanceled;
                }

                if (isCanceled && !node.Value.NotAnalyzed)
                {
                    remaining++;
                    node.MoveNext();
                    continue;
                }

                ActivityTracker.OnEnqueueModule(node.Value.Module.FilePath);

                if (Interlocked.Increment(ref _runningTasks) >= _maxTaskRunning || _walker.Remaining == 1)
                {
                    RunAnalysis(node, stopWatch);
                }
                else
                {
                    ace.AddOne();
                    StartAnalysis(node, ace, stopWatch).DoNotWait();
                }
            }

            await ace.WaitAsync(_analyzerCancellationToken);

            lock (_syncObj) {
                isCanceled = _isCanceled;
            }

            if (_walker.MissingKeys.Count == 0 || _walker.MissingKeys.All(k => k.IsTypeshed))
            {
                Interlocked.Exchange(ref _runningTasks, 0);

                if (!isCanceled)
                {
                    _analysisCompleteEvent.Set();
                }
            }
            else if (!isCanceled && _log != null && _log.LogLevel >= TraceEventType.Verbose)
            {
                _log?.Log(TraceEventType.Verbose, $"Missing keys: {string.Join(", ", _walker.MissingKeys)}");
            }

            return(remaining);
        }
コード例 #2
0
        private async Task <int> AnalyzeAffectedEntriesAsync(Stopwatch stopWatch)
        {
            IDependencyChainNode node;
            var remaining = 0;

            while ((node = await _walker.GetNextAsync(_analyzerCancellationToken)) != null)
            {
                var taskLimitReached = false;
                lock (_syncObj) {
                    if (_isCanceled)
                    {
                        switch (node)
                        {
                        case IDependencyChainLoopNode <PythonAnalyzerEntry> loop:
                            // Loop analysis is not cancellable or else small
                            // inner loops of a larger loop will not be analyzed
                            // correctly as large loop may cancel inner loop pass.
                            break;

                        case IDependencyChainSingleNode <PythonAnalyzerEntry> single when !single.Value.NotAnalyzed:
                            remaining++;
                            node.MoveNext();
                            continue;
                        }
                    }

                    taskLimitReached = _ace.Count >= _maxTaskRunning || _walker.Remaining == 1;
                    _ace.AddOne();
                }

                if (taskLimitReached)
                {
                    RunAnalysis(node, stopWatch);
                }
                else
                {
                    StartAnalysis(node, stopWatch).DoNotWait();
                }
            }

            await _ace.WaitAsync(_analyzerCancellationToken);

            lock (_syncObj) {
                if (_walker.MissingKeys.Count == 0 || _walker.MissingKeys.All(k => k.IsTypeshed))
                {
                    Debug.Assert(_ace.Count == 0);
                }
                else if (!_isCanceled && _log != null && _log.LogLevel >= TraceEventType.Verbose)
                {
                    _log?.Log(TraceEventType.Verbose, $"Missing keys: {string.Join(", ", _walker.MissingKeys)}");
                }
            }

            return(remaining);
        }
コード例 #3
0
        private async Task <int> AnalyzeAffectedEntriesAsync(Stopwatch stopWatch, CancellationToken cancellationToken)
        {
            IDependencyChainNode <PythonAnalyzerEntry> node;
            var remaining = 0;
            var ace       = new AsyncCountdownEvent(0);

            while ((node = await _walker.GetNextAsync(cancellationToken)) != null)
            {
                bool isCanceled;
                lock (_syncObj) {
                    isCanceled = _isCanceled;
                }

                if (isCanceled && !node.Value.NotAnalyzed)
                {
                    remaining++;
                    node.Skip();
                    continue;
                }

                if (Interlocked.Increment(ref _runningTasks) >= _maxTaskRunning || _walker.Remaining == 1)
                {
                    Analyze(node, null, stopWatch, cancellationToken);
                }
                else
                {
                    StartAnalysis(node, ace, stopWatch, cancellationToken).DoNotWait();
                }
            }

            await ace.WaitAsync(cancellationToken);

            if (_walker.MissingKeys.All(k => k.IsTypeshed))
            {
                Interlocked.Exchange(ref _runningTasks, 0);
                bool isCanceled;
                lock (_syncObj) {
                    isCanceled = _isCanceled;
                }

                if (!isCanceled)
                {
                    _analysisCompleteEvent.Set();
                }
            }

            return(remaining);
        }