7#include <system/action.h>
8#include <system/func.h>
9#include <system/object.h>
10#include <system/threading/tasks/task_utils.h>
12namespace System {
namespace Threading {
namespace Tasks {
22 typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
48 typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
93 int32_t _maxDegreeOfParallelism;
111 template <
typename TSource>
115 parallelOptions->get_CancellationToken().ThrowIfCancellationRequested();
117 auto enumerator = source->GetEnumerator();
118 auto tasks = MakeArray<TaskPtr>(parallelOptions->get_EffectiveMaxConcurrencyLevel());
119 auto lock = MakeObject<Object>();
121 for (
auto& task : tasks)
123 task =
MakeAsync([=, &lock, &enumerator, &body](System::Details::AsyncContext& __)
mutable
125 if (parallelOptions->get_CancellationToken().get_IsCancellationRequested())
132 LockContext __guard((lock).GetPointer());
133 if (enumerator->MoveNext())
135 value = enumerator->get_Current();
157 template<
typename TSource>
160 return ForEach(source, s_defaultParallelOptions, body);
Interface of object providing enumerator on contained elements.
Definition: ienumerable.h:25
Base class that enables using methods available for System.Object class in C#. All non-trivial classe...
Definition: object.h:62
Pointer class to wrap types being allocated on heap. Use it to manage memory for classes inheriting O...
Definition: smart_ptr.h:180
Propagates notification that operations should be canceled. This class provides a mechanism for coope...
Definition: cancellation_token.h:43
Provides support for parallel loops and regions.
Definition: parallel.h:101
static ParallelLoopResult ForEach(const SharedPtr< Collections::Generic::IEnumerable< TSource > > &source, const Action< TSource > &body)
Executes a foreach operation on an IEnumerable in which iterations may run in parallel.
Definition: parallel.h:158
static ParallelLoopResult ForEach(const SharedPtr< Collections::Generic::IEnumerable< TSource > > &source, const SharedPtr< ParallelOptions > ¶llelOptions, const Action< TSource > &body)
Executes a foreach operation on an IEnumerable in which iterations may run in parallel.
Definition: parallel.h:112
static SharedPtr< ParallelOptions > s_defaultParallelOptions
Default ParallelOptions instance used when no options are specified.
Definition: parallel.h:166
Provides completion status of a Parallel loop.
Definition: parallel.h:18
bool get_IsCompleted()
Gets whether the loop ran to completion.
Definition: parallel.h:30
ParallelLoopResult()
Constructs a ParallelLoopResult.
Definition: parallel.h:26
bool _completed
Indicates if the loop completed.
Definition: parallel.h:37
Nullable< int64_t > get_LowestBreakIteration()
Gets the lowest iteration index at which a break occurred.
Definition: parallel.h:34
Nullable< int64_t > _lowestBreakIteration
Stores the lowest break iteration index.
Definition: parallel.h:38
Stores options that configure the operation of methods on the Parallel class.
Definition: parallel.h:44
int32_t get_MaxDegreeOfParallelism()
Gets the maximum degree of parallelism enabled by this ParallelOptions instance.
Definition: parallel.h:66
void set_MaxDegreeOfParallelism(int32_t value)
Sets the maximum degree of parallelism enabled by this ParallelOptions instance.
Definition: parallel.h:70
int32_t get_EffectiveMaxConcurrencyLevel()
Gets the effective maximum concurrency level.
void set_TaskScheduler(const SharedPtr< TaskScheduler > &value)
Sets the TaskScheduler associated with this ParallelOptions instance.
Definition: parallel.h:62
void set_CancellationToken(const CancellationToken &value)
Sets the CancellationToken associated with this ParallelOptions instance.
Definition: parallel.h:78
ParallelOptions()
Constructs a ParallelOptions instance with default values.
const SharedPtr< TaskScheduler > & get_TaskScheduler()
Gets the TaskScheduler associated with this ParallelOptions instance.
Definition: parallel.h:58
SharedPtr< TaskScheduler > get_EffectiveTaskScheduler()
Gets the effective TaskScheduler to use.
const CancellationToken & get_CancellationToken()
Gets the CancellationToken associated with this ParallelOptions instance.
Definition: parallel.h:74
void WaitAll(const ArrayPtr< TaskPtr > &tasks, const CancellationToken &cancellationToken)
Waits for all of the provided Task objects to complete execution.
Definition: db_command.h:9
TaskPtr MakeAsync(const Details::AsyncFunction &fnc)
MulticastDelegate< void(Args...)> Action
Delegate type that references methods that have no return value.
Definition: action.h:40