5 // Jérémie "Garuma" Laval <jeremie.laval@gmail.com>
7 // Copyright (c) 2010 Jérémie "Garuma" Laval
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
29 using System.Threading;
31 namespace System.Linq.Parallel
33 internal class QueryOptions
35 public ParallelMergeOptions? Options {
40 public ParallelExecutionMode? Mode {
45 public CancellationToken Token {
49 /* This token is to be used by some operator (like Take) to tell that
50 * the execution of the query can be prematurly stopped
52 * It is set when passing QueryOptions to the different node's Get method
53 * and ParallelExecuter should check after the call to this method is this guy has been
54 * set. Operator may chain up multiple cancellation token that way.
55 * When checking for this token, the task body should simply return.
57 public CancellationToken ImplementerToken {
62 public bool UseStrip {
67 public bool? BehindOrderGuard {
72 public int PartitionCount {
77 public Tuple<bool, bool, bool> PartitionerSettings {
82 public CancellationToken MergedToken {
87 public bool ShouldBeSequential {
92 public QueryOptions (ParallelMergeOptions? options,
93 ParallelExecutionMode? mode,
94 CancellationToken token,
96 bool? behindOrderGuard,
98 CancellationToken implementerToken,
99 bool shouldBeSequential)
105 BehindOrderGuard = behindOrderGuard;
106 PartitionCount = partitionCount;
107 PartitionerSettings = null;
108 ImplementerToken = implementerToken;
109 ShouldBeSequential = shouldBeSequential;
111 MergeTokens (token, implementerToken);
114 void MergeTokens (CancellationToken token, CancellationToken implementerToken)
116 bool implementedNone = implementerToken == CancellationToken.None;
117 bool tokenNone = token == CancellationToken.None;
118 if (!implementedNone && !tokenNone)
119 MergedToken = CancellationTokenSource.CreateLinkedTokenSource (implementerToken, token).Token;
120 else if (implementedNone && !tokenNone)
122 else if (!implementedNone && tokenNone)
123 MergedToken = implementerToken;
125 MergedToken = CancellationToken.None;