Add atomic 128-bit compare-exchange function
Some checks failed
Builds / ExectOS (amd64, release) (push) Failing after 29s
Builds / ExectOS (i686, debug) (push) Failing after 26s
Builds / ExectOS (amd64, debug) (push) Failing after 41s
Builds / ExectOS (i686, release) (push) Failing after 36s

This commit is contained in:
2026-06-23 10:40:13 +02:00
parent 5475d970c4
commit d10b2cc2a1
2 changed files with 38 additions and 0 deletions

View File

@@ -52,6 +52,9 @@ namespace RTL
STATIC XTFASTCALL LONG_PTR CompareExchange64(IN PLONG_PTR Address,
IN LONG_PTR Comperand,
IN LONG_PTR Exchange);
STATIC XTFASTCALL DOUBLE_ULONG_PTR CompareExchange128(IN PDOUBLE_ULONG_PTR Address,
IN DOUBLE_ULONG_PTR Comperand,
IN DOUBLE_ULONG_PTR Exchange);
STATIC XTFASTCALL PVOID CompareExchangePointer(IN PVOID *Address,
IN PVOID Comperand,
IN PVOID Exchange);

View File

@@ -341,6 +341,41 @@ RTL::Atomic::CompareExchange64(IN PLONG_PTR Address,
return __sync_val_compare_and_swap(Address, Comperand, Exchange);
}
/**
* Performs an atomic compare-exchange operation on the 64-bit or 128-bit value depending on architecture.
*
* @param Address
* Supplies the address of the value to compare and potentially exchange.
*
* @param Comperand
* Supplies the value to compare against.
*
* @param Exchange
* Supplies the value to write if the comparison returns equality.
*
* @return This routine returns the original value at the given address.
*
* @since XT 1.0
*/
XTFASTCALL
DOUBLE_ULONG_PTR
RTL::Atomic::CompareExchange128(IN PDOUBLE_ULONG_PTR Address,
IN DOUBLE_ULONG_PTR Comperand,
IN DOUBLE_ULONG_PTR Exchange)
{
DOUBLE_ULONG_PTR Value;
/* Make a local copy of the comperand */
Value = Comperand;
/* Perform an atomic compare-exchange operation */
__atomic_compare_exchange((VOLATILE PDOUBLE_ULONG_PTR)Address, &Value, &Exchange,
FALSE, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
/* Return value */
return Value;
}
/**
* Performs atomically compare exchange operation.
*