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:
Ruiyu Ni
2018-09-07 17:26:14 +08:00
parent ca3e4f8ab8
commit 17634d026f
16 changed files with 56 additions and 152 deletions

View File

@@ -1,6 +1,6 @@
;------------------------------------------------------------------------------
;
; Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
; Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
; This program and the accompanying materials
; are licensed and made available under the terms and conditions of the BSD License
; which accompanies this distribution. The full text of the license may be found at
@@ -32,8 +32,8 @@
;------------------------------------------------------------------------------
global ASM_PFX(InternalSyncDecrement)
ASM_PFX(InternalSyncDecrement):
mov eax, [esp + 4]
lock dec dword [eax]
mov eax, [eax]
mov ecx, [esp + 4]
mov eax, 0FFFFFFFFh
lock xadd dword [ecx], eax
dec eax
ret