Example #1
0
 internal static Task[] Process <TSource, TElement> (QueryBaseNode <TSource> node,
                                                     Action <TElement, CancellationToken> call,
                                                     Func <QueryBaseNode <TSource>, QueryOptions, IList <IEnumerable <TElement> > > acquisitionFunc,
                                                     QueryOptions options)
 {
     return(Process <TSource, TElement> (node, call, acquisitionFunc, null, options));
 }
Example #2
0
        internal static void ProcessAndBlock <T> (QueryBaseNode <T> node, Action <T, CancellationToken> call)
        {
            QueryOptions options = CheckQuery(node, true);

            Task[] tasks = Process(node, call, (n, o) => n.GetEnumerables(o), options);
            Task.WaitAll(tasks, options.Token);
        }
Example #3
0
        internal static QueryOptions CheckQuery <T> (QueryBaseNode <T> startingNode, int partitionCount)
        {
            QueryCheckerVisitor visitor = new QueryCheckerVisitor(partitionCount);

            startingNode.Visit(visitor);

            return(visitor.Options);
        }
Example #4
0
        internal static bool IsOrdered <TSource> (this QueryBaseNode <TSource> source)
        {
            QueryIsOrderedVisitor visitor = new QueryIsOrderedVisitor();

            source.Visit(visitor);

            return(visitor.BehindOrderGuard);
        }
Example #5
0
 public QuerySymbol(
     ISymbol containingSymbol,
     QueryBaseNode declaration,
     DiagnosticBag diagnostics)
     : base(containingSymbol)
 {
     // TODO query
 }
Example #6
0
        internal static Action ProcessAndCallback <T> (QueryBaseNode <T> node, Action <T, CancellationToken> call,
                                                       Action callback, QueryOptions options)
        {
            Task[] tasks = Process(node, call, (n, o) => n.GetEnumerables(o), options);
            if (callback != null)
            {
                Task.Factory.ContinueWhenAll(tasks, (_) => callback());
            }

            return(() => Task.WaitAll(tasks, options.Token));
        }
Example #7
0
        internal static Action ProcessAndCallback <T> (QueryBaseNode <T> node, Action <KeyValuePair <long, T>, CancellationToken> call,
                                                       Action endAction,
                                                       Action callback, QueryOptions options)
        {
            Task[] tasks = Process(node, call, new QueryBaseNodeHelper <T> ().GetOrderedEnumerables, endAction, options);
            if (callback != null)
            {
                Task.Factory.ContinueWhenAll(tasks, (_) => callback());
            }

            return(() => Task.WaitAll(tasks, options.Token));
        }
Example #8
0
        internal static Task[] Process <TSource, TElement> (QueryBaseNode <TSource> node,
                                                            Action <TElement, CancellationToken> call,
                                                            Func <QueryBaseNode <TSource>, QueryOptions, IList <IEnumerable <TElement> > > acquisitionFunc,
                                                            Action endAction,
                                                            QueryOptions options)
        {
            CancellationTokenSource src
                = CancellationTokenSource.CreateLinkedTokenSource(options.ImplementerToken, options.Token);

            IList <IEnumerable <TElement> > enumerables = acquisitionFunc(node, options);

            Task[] tasks = new Task[enumerables.Count];

            for (int i = 0; i < tasks.Length; i++)
            {
                int index = i;
                tasks[i] = Task.Factory.StartNew(() => {
                    try {
                        foreach (TElement item in enumerables[index])
                        {
                            if (!CheckTokens(options))
                            {
                                break;
                            }

                            try {
                                call(item, src.Token);
                            } catch (OperationCanceledException canceledException) {
                                if (canceledException.CancellationToken != src.Token)
                                {
                                    throw canceledException;
                                }
                            }

                            if (!CheckTokens(options))
                            {
                                break;
                            }
                        }
                    } finally {
                        if (endAction != null)
                        {
                            endAction();
                        }
                    }
                }, options.Token, TaskCreationOptions.AttachedToParent | TaskCreationOptions.LongRunning, TaskScheduler.Default);
            }

            return(tasks);
        }
Example #9
0
        internal static void ProcessAndAggregate <T, U> (QueryBaseNode <T> node,
                                                         Func <U> seedFunc,
                                                         Func <U, T, U> localCall,
                                                         Action <IList <U> > call)
        {
            QueryOptions options = CheckQuery(node, true);

            IList <IEnumerable <T> > enumerables = node.GetEnumerables(options);

            U[]    locals = new U[enumerables.Count];
            Task[] tasks  = new Task[enumerables.Count];

            if (seedFunc != null)
            {
                for (int i = 0; i < locals.Length; i++)
                {
                    locals[i] = seedFunc();
                }
            }

            for (int i = 0; i < tasks.Length; i++)
            {
                var procSlot = new AggregateProcessSlot <T, U> (options,
                                                                i,
                                                                enumerables[i].GetEnumerator(),
                                                                locals,
                                                                localCall,
                                                                seedFunc);

                tasks[i] = Task.Factory.StartNew(procSlot.Process, options.Token);
            }

            Task.WaitAll(tasks, options.Token);

            if (call != null)
            {
                call(locals);
            }
        }
Example #10
0
        internal ParallelQueryEnumerator(QueryBaseNode <T> node)
        {
            this.options = ParallelExecuter.CheckQuery(node);

            if (options.ShouldBeSequential && options.Mode != ParallelExecutionMode.ForceParallelism)
            {
                IEnumerable <T> buffer = node.GetSequential();
                loader = buffer.GetEnumerator();
            }
            else
            {
                Setup();

                // Launch adding to the buffer asynchronously via Tasks
                if (options.BehindOrderGuard.Value)
                {
                    waitAction = ParallelExecuter.ProcessAndCallback(node,
                                                                     ordEnumerator.Add,
                                                                     ordEnumerator.EndParticipation,
                                                                     ordEnumerator.Stop,
                                                                     options);
                }
                else
                {
                    waitAction = ParallelExecuter.ProcessAndCallback(node,
                                                                     buffer.Add,
                                                                     buffer.CompleteAdding,
                                                                     options);
                }

                if (options.Options.HasValue && options.Options.Value == ParallelMergeOptions.FullyBuffered)
                {
                    waitAction();
                }
            }
        }
Example #11
0
		public void Visit (QueryBaseNode node)
		{

		}
Example #12
0
		public void Visit (QueryBaseNode node)
		{
			// Nothing to do atm. Later we can check if the node is a
			// Take or a Skip and set accordingly UseStrip
		}
Example #13
0
 public void Visit <T> (QueryBaseNode <T> node)
 {
 }
Example #14
0
 public void Visit(QueryBaseNode node)
 {
 }
Example #15
0
 internal IList <IEnumerable <T> > GetEnumerables(QueryBaseNode <T> source, QueryOptions options)
 {
     return(source.GetEnumerables(options));
 }
Example #16
0
 internal static QueryOptions CheckQuery <T> (QueryBaseNode <T> startingNode, bool blocking)
 {
     return(CheckQuery(startingNode, GetBestWorkerNumber(blocking)));
 }
Example #17
0
 internal static QueryOptions CheckQuery <T> (QueryBaseNode <T> startingNode)
 {
     return(CheckQuery <T> (startingNode, false));
 }
Example #18
0
 internal IList <IEnumerable <KeyValuePair <long, T> > > GetOrderedEnumerables(QueryBaseNode <T> source, QueryOptions options)
 {
     return(source.GetOrderedEnumerables(options));
 }
Example #19
0
 public void Visit(QueryBaseNode node)
 {
     // Nothing to do atm. Later we can check if the node is a
     // Take or a Skip and set accordingly UseStrip
 }