W3cubDocs

/D

core.atomic

The atomic module provides basic support for lock-free concurrent programming.

License:
Boost License 1.0
Authors:
Sean Kelly, Alex Rønne Petersen, Manu Evans
Source
core/atomic.d
pure nothrow @nogc @safe TailShared!T atomicOp(string op, T, V1)(ref shared T val, V1 mod)
Constraints: if (__traits(compiles, mixin("*cast(T*)&val" ~ op ~ "mod")));

Performs the binary operation 'op' on val using 'mod' as the modifier.

Parameters:
T val The target variable.
V1 mod The modifier to apply.
Returns:
The result of the operation.
pure nothrow @nogc @safe shared(T) atomicExchange(MemoryOrder ms = MemoryOrder.seq, T, V)(shared(T)* here, V exchangeWith)
Constraints: if (!is(T == class) && !is(T U : U*) && __traits(compiles, () { *here = exchangeWith; } ));

pure nothrow @nogc @safe shared(T) atomicExchange(MemoryOrder ms = MemoryOrder.seq, T, V)(shared(T)* here, shared(V) exchangeWith)
Constraints: if (is(T == class) && __traits(compiles, () { *here = exchangeWith; } ));

pure nothrow @nogc @safe shared(T) atomicExchange(MemoryOrder ms = MemoryOrder.seq, T, V)(shared(T)* here, shared(V)* exchangeWith)
Constraints: if (is(T U : U*) && __traits(compiles, () { *here = exchangeWith; } ));

Exchange exchangeWith with the memory referenced by here. This operation is both lock-free and atomic.

Parameters:
shared(T)* here The address of the destination variable.
V exchangeWith The value to exchange.
Returns:
The value held previously by here.
pure nothrow @nogc @safe bool cas(T, V1, V2)(shared(T)* here, const V1 ifThis, V2 writeThis)
Constraints: if (!is(T == class) && !is(T U : U*) && __traits(compiles, () { *here = writeThis; } ));

pure nothrow @nogc @safe bool cas(T, V1, V2)(shared(T)* here, const shared(V1) ifThis, shared(V2) writeThis)
Constraints: if (is(T == class) && __traits(compiles, () { *here = writeThis; } ));

pure nothrow @nogc @safe bool cas(T, V1, V2)(shared(T)* here, const shared(V1)* ifThis, shared(V2)* writeThis)
Constraints: if (is(T U : U*) && __traits(compiles, () { *here = writeThis; } ));

Stores 'writeThis' to the memory referenced by 'here' if the value referenced by 'here' is equal to 'ifThis'. This operation is both lock-free and atomic.

Parameters:
shared(T)* here The address of the destination variable.
V2 writeThis The value to store.
V1 ifThis The comparison value.
Returns:
true if the store occurred, false if not.
pure nothrow @nogc @safe bool cas(T, V1, V2)(shared(T)* here, V1* ifThis, V2 writeThis)
Constraints: if (!is(T == class) && !is(T U : U*) && __traits(compiles, () { *here = writeThis; } ));

pure nothrow @nogc @safe bool cas(T, V1, V2)(shared(T)* here, shared(V1)* ifThis, shared(V2) writeThis)
Constraints: if (is(T == class) && __traits(compiles, () { *here = writeThis; } ));

pure nothrow @nogc @safe bool cas(T, V1, V2)(shared(T)* here, shared(V1)** ifThis, shared(V2)* writeThis)
Constraints: if (is(T U : U*) && __traits(compiles, () { *here = writeThis; } ));

Stores 'writeThis' to the memory referenced by 'here' if the value referenced by 'here' is equal to the value referenced by 'ifThis'. The prior value referenced by 'here' is written to ifThis and returned to the user. This operation is both lock-free and atomic.

Parameters:
shared(T)* here The address of the destination variable.
V2 writeThis The value to store.
V1* ifThis The address of the value to compare, and receives the prior value of here as output.
Returns:
true if the store occurred, false if not.
pure nothrow @nogc @safe TailShared!T atomicLoad(MemoryOrder ms = MemoryOrder.seq, T)(ref const shared T val);

Loads 'val' from memory and returns it. The memory barrier specified by 'ms' is applied to the operation, which is fully sequenced by default. Valid memory orders are MemoryOrder.raw, MemoryOrder.acq, and MemoryOrder.seq.

Parameters:
T val The target variable.
Returns:
The value of 'val'.
pure nothrow @nogc @safe void atomicStore(MemoryOrder ms = MemoryOrder.seq, T, V1)(ref shared T val, V1 newval)
Constraints: if (__traits(compiles, () { val = newval; } ));

Writes 'newval' into 'val'. The memory barrier specified by 'ms' is applied to the operation, which is fully sequenced by default. Valid memory orders are MemoryOrder.raw, MemoryOrder.rel, and MemoryOrder.seq.

Parameters:
T val The target variable.
V1 newval The value to store.
enum MemoryOrder: int;

Specifies the memory ordering semantics of an atomic operation.

See Also:
en.cppreference.com/w/cpp/atomic/memory_order
raw

Not sequenced. Corresponds to LLVM AtomicOrdering.Monotonic and C++11/C11 memory_order_relaxed.

acq

Hoist-load + hoist-store barrier. Corresponds to LLVM AtomicOrdering.Acquire and C++11/C11 memory_order_acquire.

rel

Sink-load + sink-store barrier. Corresponds to LLVM AtomicOrdering.Release and C++11/C11 memory_order_release.

seq

Fully sequenced (acquire + release). Corresponds to LLVM AtomicOrdering.SequentiallyConsistent and C++11/C11 memory_order_seq_cst.

nothrow @nogc void atomicFence();

Inserts a full load/store memory fence (on platforms that need it). This ensures that all loads and stores before a call to this function are executed before any loads and stores after the call.

© 1999–2019 The D Language Foundation
Licensed under the Boost License 1.0.
https://dlang.org/phobos/core_atomic.html