Beispiel #1
0
                    private bool GetNextWorkItem(
                        out WorkItem workItem,
                        out CancellationToken cancellationToken
                        )
                    {
                        // GetNextWorkItem since it can't fail. we still return bool to confirm that this never fail.
                        var documentId = _processor._documentTracker?.TryGetActiveDocument();

                        if (documentId != null)
                        {
                            if (
                                _workItemQueue.TryTake(
                                    documentId,
                                    out workItem,
                                    out cancellationToken
                                    )
                                )
                            {
                                return(true);
                            }
                        }

                        return(_workItemQueue.TryTakeAnyWork(
                                   preferableProjectId: null,
                                   dependencyGraph: _processor.DependencyGraph,
                                   analyzerService: _processor.DiagnosticAnalyzerService,
                                   workItem: out workItem,
                                   cancellationToken: out cancellationToken
                                   ));
                    }
Beispiel #2
0
                    protected override async Task ExecuteAsync()
                    {
                        if (this.CancellationToken.IsCancellationRequested)
                        {
                            return;
                        }

                        var source = new TaskCompletionSource <object>();

                        try
                        {
                            // mark it as running
                            _running = source.Task;

                            // we wait for global operation if there is anything going on
                            await GlobalOperationWaitAsync().ConfigureAwait(false);

                            // we wait for higher processor to finish its working
                            await this.Processor._highPriorityProcessor.Running.ConfigureAwait(false);

                            // okay, there must be at least one item in the map
                            await ResetStatesAsync().ConfigureAwait(false);

                            if (await TryProcessOneHigherPriorityDocumentAsync().ConfigureAwait(false))
                            {
                                // successfully processed a high priority document.
                                return;
                            }

                            // process one of documents remaining
                            var      documentCancellation = default(CancellationTokenSource);
                            WorkItem workItem;
                            if (!_workItemQueue.TryTakeAnyWork(_currentProjectProcessing, out workItem, out documentCancellation))
                            {
                                return;
                            }

                            // check whether we have been shutdown
                            if (this.CancellationToken.IsCancellationRequested)
                            {
                                return;
                            }

                            // check whether we have moved to new project
                            SetProjectProcessing(workItem.ProjectId);

                            // process the new document
                            await ProcessDocumentAsync(this.Analyzers, workItem, documentCancellation).ConfigureAwait(false);
                        }
                        catch (Exception e) when(FatalError.ReportUnlessCanceled(e))
                        {
                            throw ExceptionUtilities.Unreachable;
                        }
                        finally
                        {
                            // mark it as done running
                            source.SetResult(null);
                        }
                    }
                    protected override async Task ExecuteAsync()
                    {
                        if (CancellationToken.IsCancellationRequested)
                        {
                            return;
                        }

                        var source = new TaskCompletionSource <object?>();

                        try
                        {
                            // mark it as running
                            _running = source.Task;

                            await WaitForHigherPriorityOperationsAsync().ConfigureAwait(false);

                            // okay, there must be at least one item in the map
                            await ResetStatesAsync().ConfigureAwait(false);

                            if (await TryProcessOneHigherPriorityDocumentAsync().ConfigureAwait(false))
                            {
                                // successfully processed a high priority document.
                                return;
                            }

                            // process one of documents remaining
                            if (!_workItemQueue.TryTakeAnyWork(
                                    _currentProjectProcessing, Processor.DependencyGraph, Processor.DiagnosticAnalyzerService,
                                    out var workItem, out var documentCancellation))
                            {
                                return;
                            }

                            // check whether we have been shutdown
                            if (CancellationToken.IsCancellationRequested)
                            {
                                return;
                            }

                            // check whether we have moved to new project
                            SetProjectProcessing(workItem.ProjectId);

                            // process the new document
                            await ProcessDocumentAsync(Analyzers, workItem, documentCancellation).ConfigureAwait(false);
                        }
                        catch (Exception e) when(FatalError.ReportUnlessCanceled(e))
                        {
                            throw ExceptionUtilities.Unreachable;
                        }
                        finally
                        {
                            // mark it as done running
                            source.SetResult(null);
                        }
                    }
                    private bool GetNextWorkItem(out WorkItem workItem, out CancellationTokenSource documentCancellation)
                    {
                        var documentId = _processor._documentTracker.GetActiveDocument();

                        if (documentId != null)
                        {
                            if (_workItemQueue.TryTake(documentId, out workItem, out documentCancellation))
                            {
                                return(true);
                            }
                        }

                        return(_workItemQueue.TryTakeAnyWork(preferableProjectId: null, workItem: out workItem, source: out documentCancellation));
                    }
Beispiel #5
0
                    private bool GetNextWorkItem(out WorkItem workItem, out CancellationTokenSource documentCancellation)
                    {
                        // GetNextWorkItem since it can't fail. we still return bool to confirm that this never fail.
                        var documentId = _processor._documentTracker.GetActiveDocument();

                        if (documentId != null)
                        {
                            if (_workItemQueue.TryTake(documentId, out workItem, out documentCancellation))
                            {
                                return(true);
                            }
                        }

                        return(_workItemQueue.TryTakeAnyWork(
                                   preferableProjectId: null,
                                   dependencyGraph: this._processor.DependencyGraph,
                                   workItem: out workItem,
                                   source: out documentCancellation));
                    }