Implement RtlAtomicBitTestAndSet() and RtlAtomicBitTestAndSet64() intrinsic routines

This commit is contained in:
Rafal Kupiec 2024-02-04 22:34:13 +01:00
parent 9ce841e957
commit abdb9b25db
Signed by: belliash
GPG Key ID: 4E829243E0CFE6B4
2 changed files with 52 additions and 0 deletions

View File

@ -33,6 +33,16 @@ LONG_PTR
RtlAtomicAnd64(IN VOLATILE PLONG_PTR Address,
IN LONG_PTR Mask);
XTFASTCALL
UCHAR
RtlAtomicBitTestAndSet(IN VOLATILE PLONG Base,
IN LONG Offset);
XTFASTCALL
UCHAR
RtlAtomicBitTestAndSet64(IN VOLATILE PLONGLONG Base,
IN LONGLONG Offset);
XTFASTCALL
CHAR
RtlAtomicCompareExchange8(IN VOLATILE PCHAR Address,

View File

@ -93,6 +93,48 @@ RtlAtomicAnd64(IN VOLATILE PLONG_PTR Address,
return __sync_fetch_and_and(Address, Mask);
}
/**
* Performs an atomic test of the specified bit of the specified long value and sets it to 1.
*
* @param Base
* Specifies a pointer to the variable.
*
* @param Offset
* Specifies the bit position to be tested.
*
* @return Returns a value of the specified bit.
*
* @since XT 1.0
*/
XTFASTCALL
UCHAR
RtlAtomicBitTestAndSet(IN VOLATILE PLONG Base,
IN LONG Offset)
{
return (__atomic_fetch_or(Base, 1l << Offset, __ATOMIC_SEQ_CST) >> Offset) & 1;
}
/**
* Performs an atomic test of the specified bit of the specified 64-bit long value and sets it to 1.
*
* @param Base
* Specifies a pointer to the variable.
*
* @param Offset
* Specifies the bit position to be tested.
*
* @return Returns a value of the specified bit.
*
* @since XT 1.0
*/
XTFASTCALL
UCHAR
RtlAtomicBitTestAndSet64(IN VOLATILE PLONGLONG Base,
IN LONGLONG Offset)
{
return (__atomic_fetch_or(Base, 1ll << Offset, __ATOMIC_SEQ_CST) >> Offset) & 1;
}
/**
* Performs atomically compare exchange operation on the 8-bit value.
*