Skip to content
Merged
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
77 changes: 77 additions & 0 deletions druntime/src/core/internal/atomic.d
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,83 @@ module core.internal.atomic;
import core.atomic : has128BitCAS, MemoryOrder;

version (DigitalMars)
version (AArch64)
{
/* These functions are all stubbed out. They await someone who knows what
they are doing with AArch64 atomics.
*/
enum IsAtomicLockFree(T) = T.sizeof <= size_t.sizeof * 2;

inout(T) atomicLoad(MemoryOrder order = MemoryOrder.seq, T)(inout(T)* src) pure nothrow @nogc @trusted
if (CanCAS!T)
{
return *src;
}

void atomicStore(MemoryOrder order = MemoryOrder.seq, T)(T* dest, T value) pure nothrow @nogc @trusted
if (CanCAS!T)
{
*dest = value;
}

T atomicFetchAdd(MemoryOrder order = MemoryOrder.seq, bool result = true, T)(T* dest, T value) pure nothrow @nogc @trusted
if (is(T : ulong))
{
return *dest + value;
}

T atomicFetchSub(MemoryOrder order = MemoryOrder.seq, bool result = true, T)(T* dest, T value) pure nothrow @nogc @trusted
if (is(T : ulong))
{
return atomicFetchAdd(dest, cast(T)-cast(IntOrLong!T)value);
}

T atomicExchange(MemoryOrder order = MemoryOrder.seq, bool result = true, T)(T* dest, T value) pure nothrow @nogc @trusted
if (CanCAS!T)
{
size_t storage = void;
return *cast(T*)&storage;
}

alias atomicCompareExchangeWeak = atomicCompareExchangeStrong;

bool atomicCompareExchangeStrong(MemoryOrder succ = MemoryOrder.seq, MemoryOrder fail = MemoryOrder.seq, T)(T* dest, T* compare, T value) pure nothrow @nogc @trusted
if (CanCAS!T)
{
if (*dest != *compare)
{
*compare = *dest;
return false;
}
*dest = value;
return true;
Comment thread
WalterBright marked this conversation as resolved.
}

alias atomicCompareExchangeWeakNoResult = atomicCompareExchangeStrongNoResult;

bool atomicCompareExchangeStrongNoResult(MemoryOrder succ = MemoryOrder.seq, MemoryOrder fail = MemoryOrder.seq, T)(T* dest, const T compare, T value) pure nothrow @nogc @trusted
if (CanCAS!T)
{
if (*dest != *compare)
return false;
*dest = value;
return true;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See atomicCompareExchangeStrong without the follow up comment about result.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}

void atomicFence(MemoryOrder order = MemoryOrder.seq)() pure nothrow @nogc @trusted
{
}

void atomicSignalFence(MemoryOrder order = MemoryOrder.seq)() pure nothrow @nogc @trusted
{
// no-op, dmd doesn't reorder instructions
}

void pause() pure nothrow @nogc @trusted
{
}
}
else // X86 and X86_64
{
private
{
Expand Down
Loading