Add atomic addition functions
All checks were successful
Builds / ExectOS (amd64, release) (push) Successful in 29s
Builds / ExectOS (i686, release) (push) Successful in 30s
Builds / ExectOS (amd64, debug) (push) Successful in 51s
Builds / ExectOS (i686, debug) (push) Successful in 49s

This commit is contained in:
2026-06-21 01:36:02 +02:00
parent 95ec18a1de
commit c45b81d345
2 changed files with 116 additions and 0 deletions

View File

@@ -18,6 +18,16 @@ namespace RTL
class Atomic class Atomic
{ {
public: public:
STATIC XTFASTCALL CHAR Add8(IN PCHAR Address,
IN CHAR Value);
STATIC XTFASTCALL SHORT Add16(IN PSHORT Address,
IN SHORT Value);
STATIC XTFASTCALL LONG Add32(IN PLONG Address,
IN LONG Value);
STATIC XTFASTCALL LONG_PTR Add64(IN PLONG_PTR Address,
IN LONG_PTR Value);
STATIC XTFASTCALL PVOID AddPointer(IN PVOID *Address,
IN PVOID Value);
STATIC XTFASTCALL CHAR And8(IN PCHAR Address, STATIC XTFASTCALL CHAR And8(IN PCHAR Address,
IN CHAR Mask); IN CHAR Mask);
STATIC XTFASTCALL SHORT And16(IN PSHORT Address, STATIC XTFASTCALL SHORT And16(IN PSHORT Address,

View File

@@ -4,11 +4,117 @@
* FILE: xtoskrnl/rtl/atomic.cc * FILE: xtoskrnl/rtl/atomic.cc
* DESCRIPTION: Atomic operations support * DESCRIPTION: Atomic operations support
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org> * DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
* Aiken Harris <harraiken91@gmail.com>
*/ */
#include <xtos.hh> #include <xtos.hh>
/**
* Performs an atomic addition on the 8-bit value.
*
* @param Address
* Supplies the address of the value on which the addition is to be performed.
*
* @param Value
* Supplies the value to be added.
*
* @return This routine returns the initial value at the given address.
*
* @since XT 1.0
*/
XTFASTCALL
CHAR
RTL::Atomic::Add8(IN PCHAR Address,
IN CHAR Value)
{
return __sync_fetch_and_add(Address, Value);
}
/**
* Performs an atomic addition on the 16-bit value.
*
* @param Address
* Supplies the address of the value on which the addition is to be performed.
*
* @param Value
* Supplies the value to be added.
*
* @return This routine returns the initial value at the given address.
*
* @since XT 1.0
*/
XTFASTCALL
SHORT
RTL::Atomic::Add16(IN PSHORT Address,
IN SHORT Value)
{
return __sync_fetch_and_add(Address, Value);
}
/**
* Performs an atomic addition on the 32-bit value.
*
* @param Address
* Supplies the address of the value on which the addition is to be performed.
*
* @param Value
* Supplies the value to be added.
*
* @return This routine returns the initial value at the given address.
*
* @since XT 1.0
*/
XTFASTCALL
LONG
RTL::Atomic::Add32(IN PLONG Address,
IN LONG Value)
{
return __sync_fetch_and_add(Address, Value);
}
/**
* Performs an atomic addition on the 64-bit value.
*
* @param Address
* Supplies the address of the value on which the addition is to be performed.
*
* @param Value
* Supplies the value to be added.
*
* @return This routine returns the initial value at the given address.
*
* @since XT 1.0
*/
XTFASTCALL
LONG_PTR
RTL::Atomic::Add64(IN PLONG_PTR Address,
IN LONG_PTR Value)
{
return __sync_fetch_and_add(Address, Value);
}
/**
* Performs an atomic addition on the pointer value.
*
* @param Address
* Supplies the address of the pointer on which the addition is to be performed.
*
* @param Value
* Supplies the value (in bytes) to be added to the pointer.
*
* @return This routine returns the initial pointer value at the given address.
*
* @since XT 1.0
*/
XTFASTCALL
PVOID
RTL::Atomic::AddPointer(IN PVOID *Address,
IN PVOID Value)
{
return (PVOID)__sync_fetch_and_add(Address, Value);
}
/** /**
* Performs an atomic bitwise AND operation on the 8-bit value. * Performs an atomic bitwise AND operation on the 8-bit value.
* *