Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit 67aa4f6

Browse files
committed
Made atomicOp a bit more efficient.
1 parent 335d84f commit 67aa4f6

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/core/atomic.d

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ void atomicFence() nothrow @nogc @safe
404404
* Returns:
405405
* The result of the operation.
406406
*/
407-
TailShared!T atomicOp(string op, T, V1)(ref shared T val, V1 mod) pure nothrow @nogc @safe
407+
T atomicOp(string op, T, V1)(ref shared T val, V1 mod) pure nothrow @nogc @safe
408408
if (__traits(compiles, mixin("*cast(T*)&val" ~ op ~ "mod")))
409409
in (atomicValueIsProperlyAligned(val))
410410
{
@@ -420,7 +420,7 @@ in (atomicValueIsProperlyAligned(val))
420420
op == "==" || op == "!=" || op == "<" || op == "<=" ||
421421
op == ">" || op == ">=")
422422
{
423-
TailShared!T get = atomicLoad!(MemoryOrder.raw)(val);
423+
T get = atomicLoad!(MemoryOrder.raw, T)(val);
424424
mixin("return get " ~ op ~ " mod;");
425425
}
426426
else
@@ -430,21 +430,20 @@ in (atomicValueIsProperlyAligned(val))
430430
// |= ^= <<= >>= >>>= ~=
431431
static if (op == "+=" && __traits(isIntegral, T) && __traits(isIntegral, V1) && T.sizeof <= size_t.sizeof && V1.sizeof <= size_t.sizeof)
432432
{
433-
return cast(T)(atomicFetchAdd!(MemoryOrder.seq, T)(val, mod) + mod);
433+
return cast(T)(atomicFetchAdd(val, mod) + mod);
434434
}
435435
else static if (op == "-=" && __traits(isIntegral, T) && __traits(isIntegral, V1) && T.sizeof <= size_t.sizeof && V1.sizeof <= size_t.sizeof)
436436
{
437-
return cast(T)(atomicFetchSub!(MemoryOrder.seq, T)(val, mod) - mod);
437+
return cast(T)(atomicFetchSub(val, mod) - mod);
438438
}
439439
else static if (op == "+=" || op == "-=" || op == "*=" || op == "/=" ||
440440
op == "%=" || op == "^^=" || op == "&=" || op == "|=" ||
441441
op == "^=" || op == "<<=" || op == ">>=" || op == ">>>=") // skip "~="
442442
{
443-
TailShared!T get, set;
444-
443+
T set, get = atomicLoad!(MemoryOrder.raw, T)(val);
445444
do
446445
{
447-
get = set = atomicLoad!(MemoryOrder.raw)(val);
446+
set = get;
448447
mixin("set " ~ op ~ " mod;");
449448
} while (!casByRef(val, get, set));
450449
return set;

0 commit comments

Comments
 (0)