r6.0.1:lfds601_abstraction_cas

From liblfds.org
Jump to navigation Jump to search

Source Files

/liblfds601/src/lfds601_abstraction/lfds601_abstraction_cas.c
/liblfds601/inc/liblfds601.h

Prototype

LFDS601_INLINE lfds601_atom_t lfds601_abstraction_cas( volatile lfds601_atom_t *destination, lfds601_atom_t exchange, lfds601_atom_t compare )

Parameters

volatile lfds601_atom_t *destination

Address of the destination.

lfds601_atom_t exchange

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

lfds601_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 lfds601_abstraction_cas is distinctly different to the prototype for lfds601_abstraction_dcas. The reason for this is that lfds601_abstraction_cas works on pointer length values which can accordingly be directly passed into the function; lfds601_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
  */

  LFDS601_INLINE lfds601_atom_t lfds601_abstraction_cas( volatile lfds601_atom_t *destination, lfds601_atom_t exchange, lfds601_atom_t compare )
  {
    return( (lfds601_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