2010-05-25 Jb Evain <jbevain@novell.com>
[mcs.git] / class / System.Core / System.Linq / ParallelQuery.cs
blob6d99813c02624e93cea9414dcfc491758a7d24eb
1 //
2 // ParallelQuery.cs
3 //
4 // Author:
5 // Jérémie "Garuma" Laval <jeremie.laval@gmail.com>
6 //
7 // Copyright (c) 2010 Jérémie "Garuma" Laval
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining a copy
10 // of this software and associated documentation files (the "Software"), to deal
11 // in the Software without restriction, including without limitation the rights
12 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 // copies of the Software, and to permit persons to whom the Software is
14 // furnished to do so, subject to the following conditions:
16 // The above copyright notice and this permission notice shall be included in
17 // all copies or substantial portions of the Software.
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 // THE SOFTWARE.
27 using System;
28 using System.Threading;
29 using System.Collections;
30 using System.Collections.Generic;
31 using System.Collections.Concurrent;
33 #if NET_4_0
35 namespace System.Linq
37 public class ParallelQuery : IEnumerable
39 ParallelExecutionMode execMode = ParallelExecutionMode.Default;
40 ParallelMergeOptions mergeOptions = ParallelMergeOptions.Default;
42 internal ParallelQuery ()
47 internal ParallelMergeOptions MergeOptions {
48 get {
49 return mergeOptions;
51 set {
52 mergeOptions = value;
56 internal ParallelExecutionMode ExecMode {
57 get {
58 return execMode;
60 set {
61 execMode = value;
65 IEnumerator IEnumerable.GetEnumerator ()
67 return GetEnumeratorTrick ();
70 // Trick to get the correct IEnumerator from ParallelQuery<TSource>
71 internal virtual IEnumerator GetEnumeratorTrick ()
73 return null;
76 internal virtual ParallelQuery<object> TypedQuery {
77 get {
78 return null;
83 public class ParallelQuery<TSource> : ParallelQuery, IEnumerable<TSource>, IEnumerable
85 QueryBaseNode<TSource> node;
87 internal ParallelQuery (QueryBaseNode<TSource> node)
89 this.node = node;
92 internal QueryBaseNode<TSource> Node {
93 get {
94 return node;
98 public virtual IEnumerator<TSource> GetEnumerator ()
100 return GetEnumeratorInternal ();
103 IEnumerator IEnumerable.GetEnumerator ()
105 return (IEnumerator)GetEnumeratorInternal ();
108 IEnumerator<TSource> GetEnumeratorInternal ()
110 return new ParallelQueryEnumerator<TSource> (node);
113 internal override IEnumerator GetEnumeratorTrick ()
115 return (IEnumerator)GetEnumeratorInternal ();
118 internal override ParallelQuery<object> TypedQuery {
119 get {
120 return new ParallelQuery<object> (new QueryCastNode<TSource> (node));
125 #endif