MdePkg/SynchronizationLib: fix Interlocked[De|In]crement return value
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1197 Today's InterlockedIncrement()/InterlockedDecrement() guarantees to perform atomic increment/decrement but doesn't guarantee the return value equals to the new value. The patch fixes the behavior to use "XADD" instruction to guarantee the return value equals to the new value. The patch calls intrinsic functions for MSVC tool chain, calls the NASM implementation for INTEL tool chain and calls GCC inline assembly implementation (GccInline.c) for GCC tool chain. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com> Cc: Jiewen Yao <jiewen.yao@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com> Cc: Michael D Kinney <michael.d.kinney@intel.com>
This commit is contained in:
@@ -32,8 +32,9 @@
|
||||
;------------------------------------------------------------------------------
|
||||
global ASM_PFX(InternalSyncIncrement)
|
||||
ASM_PFX(InternalSyncIncrement):
|
||||
mov eax, [esp + 4]
|
||||
lock inc dword [eax]
|
||||
mov eax, [eax]
|
||||
mov ecx, [esp + 4]
|
||||
mov eax, 1
|
||||
lock xadd dword [ecx], eax
|
||||
inc eax
|
||||
ret
|
||||
|
||||
|
Reference in New Issue
Block a user