r6.1.1:lfds611_abstraction_cas

From liblfds.org
Revision as of 14:07, 4 January 2015 by Admin (talk | contribs) (1 revision imported)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Source Files

/liblfds611/src/lfds611_abstraction/lfds611_abstraction_cas.c
/liblfds611/src/liblfds611_internal.h

Prototype

static LFDS611_INLINE lfds611_atom_t lfds611_abstraction_cas( volatile lfds611_atom_t *destination, lfds611_atom_t exchange, lfds611_atom_t compare )

Parameters

volatile lfds611_atom_t *destination

Address of the destination.

lfds611_atom_t exchange

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

lfds611_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 lfds611_abstraction_cas is distinctly different to the prototype for lfds611_abstraction_dcas. The reason for this is that lfds611_abstraction_cas works on pointer length values which can accordingly be directly passed into the function; lfds611_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 LFDS611_INLINE lfds611_atom_t lfds611_abstraction_cas( volatile lfds611_atom_t *destination, lfds611_atom_t exchange, lfds611_atom_t compare )
  {
    return( (lfds611_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