cas

Performs either compare-and-set or compare-and-swap (or exchange).

There are two categories of overloads in this template: The first category does a simple compare-and-set. The comparison value (ifThis) is treated as an rvalue.

The second category does a compare-and-swap (a.k.a. compare-and-exchange), and expects ifThis to be a pointer type, where the previous value of here will be written.

This operation is both lock-free and atomic.

  1. bool cas(T* here, V1 ifThis, V2 writeThis)
    template cas(MemoryOrder succ = MemoryOrder.seq, MemoryOrder fail = MemoryOrder.seq)
    pure nothrow @nogc @trusted
    bool
    cas
    (
    T
    V1
    V2
    )
    (
    T* here
    ,,)
    if (
    !is(T == shared) &&
    is(T : V1)
    )
  2. bool cas(shared(T)* here, V1 ifThis, V2 writeThis)
  3. bool cas(shared(T)* here, shared(V1) ifThis, shared(V2) writeThis)
  4. bool cas(T* here, T* ifThis, V writeThis)
  5. bool cas(shared(T)* here, V1* ifThis, V2 writeThis)
  6. bool cas(shared(T)* here, shared(T)* ifThis, shared(V) writeThis)

Members

Functions

cas
bool cas(T* here, V1 ifThis, V2 writeThis)

Compare-and-set for non-shared values

cas
bool cas(shared(T)* here, V1 ifThis, V2 writeThis)

Compare-and-set for shared value type

cas
bool cas(shared(T)* here, shared(V1) ifThis, shared(V2) writeThis)

Compare-and-set for shared reference type (class)

cas
bool cas(T* here, T* ifThis, V writeThis)

Compare-and-exchange for non-shared types

cas
bool cas(shared(T)* here, V1* ifThis, V2 writeThis)

Compare and exchange for mixed-sharedness types

cas
bool cas(shared(T)* here, shared(T)* ifThis, shared(V) writeThis)

Compare-and-exchange for class

Parameters

here

The address of the destination variable.

writeThis

The value to store.

ifThis

The comparison value.

Return Value

true if the store occurred, false if not.

Meta