Difference between revisions of "r6.1.0:Lfds610 abstraction cas"

From liblfds.org
Jump to navigation Jump to search
m (1 revision imported)
 
(No difference)

Latest revision as of 14:07, 4 January 2015

Source Files

/liblfds610/src/lfds610_abstraction/lfds610_abstraction_cas.c
/liblfds610/src/liblfds610_internal.h

Prototype

static LFDS610_INLINE lfds610_atom_t lfds610_abstraction_cas( volatile lfds610_atom_t *destination, lfds610_atom_t exchange, lfds610_atom_t compare )

Parameters

volatile lfds610_atom_t *destination

Address of the destination.

lfds610_atom_t exchange

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

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

  static LFDS610_INLINE lfds610_atom_t lfds610_abstraction_cas( volatile lfds610_atom_t *destination, lfds610_atom_t exchange, lfds610_atom_t compare )
  {
    return( (lfds610_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