r6.0.0:lfds600_abstraction_cas

From liblfds.org
Jump to navigation Jump to search

Source Files

/liblfds600/src/lfds600_abstraction/lfds600_abstraction_cas.c
/liblfds600/inc/liblfds600.h

Prototype

LFDS600_INLINE lfds600_atom_t lfds600_abstraction_cas( volatile lfds600_atom_t *destination, lfds600_atom_t exchange, lfds600_atom_t compare )

Parameters

volatile lfds600_atom_t *destination

Address of the destination.

lfds600_atom_t exchange

The value of the placed into destination if destination and compare are equal.

lfds600_atom_t compare

The value to compare to destination; the value pointed to by compare must be over-written, after the compare, with the original value of destination.

Return Value

Returns the original value of *destination.

Notes

Be aware the prototype for lfds600_abstraction_cas is distinctly different to the prototype for lfds600_abstraction_dcas. The reason for this is that lfds600_abstraction_cas works on pointer length values which can accordingly be directly passed into the function; lfds600_abstraction_dcas is working on double pointer length values, which have to be passed in as a pointer to an array.

Examples

64-bit and 32-bit Windows (user-mode and kernel-mode) on any CPU

#if (defined _WIN32 && defined _MSC_VER)

  /* TRD : 64 bit and 32 bit Windows (user-mode or kernel) on any CPU with the Microsoft C compiler

           _WIN32    indicates 64-bit or 32-bit Windows
           _MSC_VER  indicates Microsoft C compiler
  */

  LFDS600_INLINE lfds600_atom_t lfds600_abstraction_cas( volatile lfds600_atom_t *destination, lfds600_atom_t exchange, lfds600_atom_t compare )
  {
    return( (lfds600_atom_t) _InterlockedCompareExchangePointer((void * volatile *) destination, (void *) exchange, (void *) compare) );
  }

#endif

_InterlockedCompareExchangePointer is a compiler instrinsic and so is available on all platforms using the MS C compiler. However, the documentation states that; "On the x86 architecture, _InterlockedCompareExchangePointer is a macro that calls _InterlockedCompareExchange." In fact, this macro is missing. To compensate, it is defined in liblfds.h, in the abstraction layer for x86 on user-mode Windows. (Kernel-mode compiles without any problems).

See Also