https://git.reactos.org/?p=reactos.git;a=commitdiff;h=d87b45bee7e57971f41f1f4aa36c2d9adc340f1b
commit d87b45bee7e57971f41f1f4aa36c2d9adc340f1b Author: Timo Kreuzer <timo.kreu...@reactos.org> AuthorDate: Sun Nov 26 17:32:27 2023 +0200 Commit: Timo Kreuzer <timo.kreu...@reactos.org> CommitDate: Fri Dec 8 19:28:57 2023 +0200 [NDK] Add Affinity helper inline functions --- hal/halx86/include/smp.h | 9 -------- ntoskrnl/include/internal/ke.h | 1 - sdk/include/ndk/kefuncs.h | 47 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 10 deletions(-) diff --git a/hal/halx86/include/smp.h b/hal/halx86/include/smp.h index d35189801c5..3b98c788ab9 100644 --- a/hal/halx86/include/smp.h +++ b/hal/halx86/include/smp.h @@ -7,15 +7,6 @@ #pragma once -#define AFFINITY_MASK(Id) ((KAFFINITY)1 << (Id)) - -/* Helper to find the lowest CPU in a KAFFINITY */ -#ifdef _WIN64 -#define BitScanForwardAffinity BitScanForward64 -#else -#define BitScanForwardAffinity BitScanForward -#endif - /* This table is filled for each physical processor on system */ typedef struct _PROCESSOR_IDENTITY { diff --git a/ntoskrnl/include/internal/ke.h b/ntoskrnl/include/internal/ke.h index fbd3660553e..6a477545c44 100644 --- a/ntoskrnl/include/internal/ke.h +++ b/ntoskrnl/include/internal/ke.h @@ -155,7 +155,6 @@ extern VOID __cdecl KiInterruptTemplate(VOID); /* MACROS *************************************************************************/ -#define AFFINITY_MASK(ProcessorIndex) ((KAFFINITY)1 << (ProcessorIndex)) #define PRIORITY_MASK(Priority) (1UL << (Priority)) /* Tells us if the Timer or Event is a Syncronization or Notification Object */ diff --git a/sdk/include/ndk/kefuncs.h b/sdk/include/ndk/kefuncs.h index 0d53714e63f..f1ac4888be8 100644 --- a/sdk/include/ndk/kefuncs.h +++ b/sdk/include/ndk/kefuncs.h @@ -33,6 +33,53 @@ extern "C" #ifndef NTOS_MODE_USER +// +// Affinity helpers +// +FORCEINLINE KAFFINITY AFFINITY_MASK(ULONG Index) +{ + ASSERT(Index < sizeof(KAFFINITY) * 8); + return (KAFFINITY)1 << Index; +} + +FORCEINLINE BOOLEAN BitScanForwardAffinity(PULONG Index, KAFFINITY Mask) +{ +#ifdef _WIN64 + return BitScanForward64(Index, Mask); +#else + return BitScanForward(Index, Mask); +#endif +} + +FORCEINLINE BOOLEAN BitScanReverseAffinity(PULONG Index, KAFFINITY Mask) +{ +#ifdef _WIN64 + return BitScanReverse64(Index, Mask); +#else + return BitScanReverse(Index, Mask); +#endif +} + +FORCEINLINE BOOLEAN InterlockedBitTestAndSetAffinity(volatile KAFFINITY *Affinity, ULONG Index) +{ + ASSERT(Index < sizeof(KAFFINITY) * 8); +#ifdef _WIN64 + return InterlockedBitTestAndSet64((PLONG64)Affinity, Index); +#else + return InterlockedBitTestAndSet((PLONG)Affinity, Index); +#endif +} + +FORCEINLINE BOOLEAN InterlockedBitTestAndResetAffinity(volatile KAFFINITY *Affinity, ULONG Index) +{ + ASSERT(Index < sizeof(KAFFINITY) * 8); +#ifdef _WIN64 + return InterlockedBitTestAndReset64((PLONG64)Affinity, Index); +#else + return InterlockedBitTestAndReset((PLONG)Affinity, Index); +#endif +} + // // APC Functions //