Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions std/parallelism.d
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,9 @@ import core.thread;

import std.algorithm;
import std.conv;
import std.exception;
import std.functional;
import std.math;
import std.meta;
import std.range;
import std.range.primitives;
import std.traits;
import std.typecons;

Expand Down Expand Up @@ -537,6 +535,7 @@ struct Task(alias fun, Args...)

private void enforcePool()
{
import std.exception : enforce;
enforce(this.pool !is null, "Job not submitted yet.");
}

Expand Down Expand Up @@ -1529,6 +1528,7 @@ public:
*/
ParallelForeach!R parallel(R)(R range, size_t workUnitSize)
{
import std.exception : enforce;
enforce(workUnitSize > 0, "workUnitSize must be > 0.");
alias RetType = ParallelForeach!R;
return RetType(this, range, workUnitSize);
Expand Down Expand Up @@ -1653,6 +1653,7 @@ public:
is(MapType!(Args[0], functions) : ElementType!(Args[$ - 1]))
)
{
import std.exception : enforce;
alias buf = args[$ - 1];
alias args2 = args[0..$ - 1];
alias Args2 = Args[0..$ - 1];
Expand All @@ -1666,6 +1667,8 @@ public:
}
else
{
import std.array : uninitializedArray;

auto buf = uninitializedArray!(MapType!(Args[0], functions)[])(len);
alias args2 = args;
alias Args2 = Args;
Expand Down Expand Up @@ -1826,6 +1829,8 @@ public:
map(S)(S source, size_t bufSize = 100, size_t workUnitSize = size_t.max)
if (isInputRange!S)
{
import std.exception : enforce;

enforce(workUnitSize == size_t.max || workUnitSize <= bufSize,
"Work unit size must be smaller than buffer size.");
alias fun = adjoin!(staticMap!(unaryFun, functions));
Expand Down Expand Up @@ -1978,6 +1983,7 @@ public:
{
static if (isRandomAccessRange!S)
{
import std.range : take;
auto toMap = take(source, buf.length);
scope(success) popSource();
}
Expand Down Expand Up @@ -2476,6 +2482,8 @@ public:
}
else
{
import std.exception : enforce;

static assert(args2.length == 1);
alias range = args2[0];

Expand Down Expand Up @@ -3183,6 +3191,7 @@ public:
@trusted void put(alias fun, Args...)(Task!(fun, Args)* task)
if (isSafeReturn!(typeof(*task)))
{
import std.exception : enforce;
enforce(task !is null, "Cannot put a null Task on a TaskPool queue.");
put(*task);
}
Expand Down Expand Up @@ -3611,6 +3620,7 @@ enum string parallelApplyMixinInputRange = q{
size_t makeTemp()
{
import std.algorithm.internal : addressOf;
import std.array : uninitializedArray;

if (temp is null)
{
Expand Down Expand Up @@ -3642,6 +3652,8 @@ enum string parallelApplyMixinInputRange = q{
// Returns: The previous value of nPopped.
static if (!bufferTrick) size_t makeTemp()
{
import std.array : uninitializedArray;

if (temp is null)
{
temp = uninitializedArray!Temp(workUnitSize);
Expand Down Expand Up @@ -3897,6 +3909,10 @@ version(unittest)
// These are the tests that should be run every time Phobos is compiled.
unittest
{
import std.exception : assertThrown;
import std.math : log, approxEqual, sqrt;
import std.range : iota;

poolInstance = new TaskPool(2);
scope(exit) poolInstance.stop();

Expand Down Expand Up @@ -4151,6 +4167,7 @@ unittest
));

{
import std.array : join, split;
import std.file : deleteme;

string temp_file = deleteme ~ "-tempDelMe.txt";
Expand Down