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

Commit

Permalink
the writeThis value must not be const to support structs with pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinNowak committed Jan 16, 2015
1 parent 8fffa42 commit 745aac0
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/core/atomic.d
Expand Up @@ -91,7 +91,7 @@ version( CoreDdoc )
* Returns:
* true if the store occurred, false if not.
*/
bool cas(T,V1,V2)( shared(T)* here, const V1 ifThis, const V2 writeThis ) nothrow
bool cas(T,V1,V2)( shared(T)* here, const V1 ifThis, V2 writeThis ) nothrow
if( !is(T == class) && !is(T U : U*) && __traits( compiles, { *here = writeThis; } ) );

/// Ditto
Expand Down Expand Up @@ -209,7 +209,7 @@ else version( AsmX86_32 )
}
}

bool cas(T,V1,V2)( shared(T)* here, const V1 ifThis, const V2 writeThis ) nothrow
bool cas(T,V1,V2)( shared(T)* here, const V1 ifThis, V2 writeThis ) nothrow
if( !is(T == class) && !is(T U : U*) && __traits( compiles, { *here = writeThis; } ) )
{
return casImpl(here, ifThis, writeThis);
Expand Down Expand Up @@ -681,7 +681,7 @@ else version( AsmX86_64 )
}


bool cas(T,V1,V2)( shared(T)* here, const V1 ifThis, const V2 writeThis ) nothrow
bool cas(T,V1,V2)( shared(T)* here, const V1 ifThis, V2 writeThis ) nothrow
if( !is(T == class) && !is(T U : U*) && __traits( compiles, { *here = writeThis; } ) )
{
return casImpl(here, ifThis, writeThis);
Expand Down Expand Up @@ -1333,6 +1333,24 @@ version( unittest )
assert(b.value1 == 3 && b.value2 ==4);
}

version (D_LP64)
{
static if (has128BitCAS) enum hasDWCAS = true;
}
else
{
static if (has64BitCAS) enum hasDWCAS = true;
}

static if (hasDWCAS)
{
static struct List { size_t gen; List* next; }
shared(List) head;
assert(cas(&head, shared(List)(0, null), shared(List)(1, cast(List*)1)));
assert(head.gen == 1);
assert(cast(size_t)head.next == 1);
}

shared(size_t) i;

atomicOp!"+="( i, cast(size_t) 1 );
Expand Down

0 comments on commit 745aac0

Please sign in to comment.