]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdePkg/SynchronizationLib: fix Interlocked[De|In]crement return value
authorRuiyu Ni <ruiyu.ni@intel.com>
Fri, 7 Sep 2018 09:26:14 +0000 (17:26 +0800)
committerRuiyu Ni <ruiyu.ni@intel.com>
Tue, 25 Sep 2018 02:02:53 +0000 (10:02 +0800)
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>
18 files changed:
MdePkg/Include/Library/SynchronizationLib.h
MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf
MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLibInternals.h
MdePkg/Library/BaseSynchronizationLib/Ia32/GccInline.c
MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedDecrement.c [deleted file]
MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedDecrement.nasm
MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedIncrement.c [deleted file]
MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedIncrement.nasm
MdePkg/Library/BaseSynchronizationLib/InterlockedDecrementMsc.c [new file with mode: 0644]
MdePkg/Library/BaseSynchronizationLib/InterlockedIncrementMsc.c [new file with mode: 0644]
MdePkg/Library/BaseSynchronizationLib/Synchronization.c
MdePkg/Library/BaseSynchronizationLib/SynchronizationGcc.c
MdePkg/Library/BaseSynchronizationLib/SynchronizationMsc.c
MdePkg/Library/BaseSynchronizationLib/X64/GccInline.c
MdePkg/Library/BaseSynchronizationLib/X64/InterlockedDecrement.c [deleted file]
MdePkg/Library/BaseSynchronizationLib/X64/InterlockedDecrement.nasm
MdePkg/Library/BaseSynchronizationLib/X64/InterlockedIncrement.c [deleted file]
MdePkg/Library/BaseSynchronizationLib/X64/InterlockedIncrement.nasm

index da69f6ff5e0e19aecaed4bfc8dc9562b4b471f42..ce3bce04f50acf66cb85c3665f1dbeeb2f9eece6 100644 (file)
@@ -144,8 +144,7 @@ ReleaseSpinLock (
 \r
   Performs an atomic increment of the 32-bit unsigned integer specified by\r
   Value and returns the incremented value. The increment operation must be\r
-  performed using MP safe mechanisms. The state of the return value is not\r
-  guaranteed to be MP safe.\r
+  performed using MP safe mechanisms.\r
 \r
   If Value is NULL, then ASSERT().\r
 \r
@@ -166,8 +165,7 @@ InterlockedIncrement (
 \r
   Performs an atomic decrement of the 32-bit unsigned integer specified by\r
   Value and returns the decremented value. The decrement operation must be\r
-  performed using MP safe mechanisms. The state of the return value is not\r
-  guaranteed to be MP safe.\r
+  performed using MP safe mechanisms.\r
 \r
   If Value is NULL, then ASSERT().\r
 \r
index 0be1d4331f072b1d0b5e207fd3f0dfb606464598..427e959f2ea8077ec981312c46598d16c1b2d210 100755 (executable)
@@ -34,9 +34,9 @@
   Ia32/InterlockedCompareExchange64.c | MSFT\r
   Ia32/InterlockedCompareExchange32.c | MSFT\r
   Ia32/InterlockedCompareExchange16.c | MSFT\r
-  Ia32/InterlockedDecrement.c | MSFT\r
-  Ia32/InterlockedIncrement.c | MSFT\r
-  SynchronizationMsc.c  | MSFT\r
+  InterlockedIncrementMsc.c | MSFT\r
+  InterlockedDecrementMsc.c | MSFT\r
+  SynchronizationMsc.c | MSFT\r
 \r
   Ia32/InterlockedCompareExchange64.nasm| INTEL\r
   Ia32/InterlockedCompareExchange32.nasm| INTEL\r
   X64/InterlockedCompareExchange64.c | MSFT\r
   X64/InterlockedCompareExchange32.c | MSFT\r
   X64/InterlockedCompareExchange16.c | MSFT\r
+  InterlockedIncrementMsc.c | MSFT\r
+  InterlockedDecrementMsc.c | MSFT\r
+  SynchronizationMsc.c | MSFT\r
 \r
   X64/InterlockedCompareExchange64.nasm| INTEL\r
   X64/InterlockedCompareExchange32.nasm| INTEL\r
   X64/InterlockedCompareExchange16.nasm| INTEL\r
-\r
-  X64/InterlockedDecrement.c | MSFT\r
-  X64/InterlockedIncrement.c | MSFT\r
-  SynchronizationMsc.c | MSFT\r
-\r
-  X64/InterlockedDecrement.nasm| INTEL\r
-  X64/InterlockedIncrement.nasm| INTEL\r
+  X64/InterlockedDecrement.nasm | INTEL\r
+  X64/InterlockedIncrement.nasm | INTEL\r
   Synchronization.c | INTEL\r
 \r
   Ia32/InternalGetSpinLockProperties.c | GCC\r
index 37edd7c1885221ae79f27f16fa125d63c6c9d864..8c363a85854c69d2dbb6135afc90f120423b1252 100644 (file)
@@ -27,8 +27,7 @@
 \r
   Performs an atomic increment of the 32-bit unsigned integer specified by\r
   Value and returns the incremented value. The increment operation must be\r
-  performed using MP safe mechanisms. The state of the return value is not\r
-  guaranteed to be MP safe.\r
+  performed using MP safe mechanisms.\r
 \r
   @param  Value A pointer to the 32-bit value to increment.\r
 \r
@@ -47,8 +46,7 @@ InternalSyncIncrement (
 \r
   Performs an atomic decrement of the 32-bit unsigned integer specified by\r
   Value and returns the decrement value. The decrement operation must be\r
-  performed using MP safe mechanisms. The state of the return value is not\r
-  guaranteed to be MP safe.\r
+  performed using MP safe mechanisms.\r
 \r
   @param  Value A pointer to the 32-bit value to decrement.\r
 \r
index 4ab293f243b8233fd2ce080b6e52f54129b69714..d82e0205f553fc95a0507df06bac016a34bcb54f 100644 (file)
@@ -20,8 +20,7 @@
 \r
   Performs an atomic increment of the 32-bit unsigned integer specified by\r
   Value and returns the incremented value. The increment operation must be\r
-  performed using MP safe mechanisms. The state of the return value is not\r
-  guaranteed to be MP safe.\r
+  performed using MP safe mechanisms.\r
 \r
   @param  Value A pointer to the 32-bit value to increment.\r
 \r
@@ -37,9 +36,10 @@ InternalSyncIncrement (
   UINT32  Result;\r
 \r
   __asm__ __volatile__ (\r
+    "movl    $1, %%eax  \n\t"\r
     "lock               \n\t"\r
-    "incl    %2         \n\t"\r
-    "movl    %2, %%eax      "\r
+    "xadd    %%eax, %2  \n\t"\r
+    "inc     %%eax          "\r
     : "=a" (Result),          // %0\r
       "=m" (*Value)           // %1\r
     : "m"  (*Value)           // %2\r
@@ -57,8 +57,7 @@ InternalSyncIncrement (
 \r
   Performs an atomic decrement of the 32-bit unsigned integer specified by\r
   Value and returns the decremented value. The decrement operation must be\r
-  performed using MP safe mechanisms. The state of the return value is not\r
-  guaranteed to be MP safe.\r
+  performed using MP safe mechanisms.\r
 \r
   @param  Value A pointer to the 32-bit value to decrement.\r
 \r
@@ -74,9 +73,10 @@ InternalSyncDecrement (
    UINT32  Result;\r
 \r
   __asm__ __volatile__ (\r
-    "lock               \n\t"\r
-    "decl    %2         \n\t"\r
-    "movl    %2, %%eax      "\r
+    "movl    $-1, %%eax  \n\t"\r
+    "lock                \n\t"\r
+    "xadd    %%eax, %2   \n\t"\r
+    "dec     %%eax                  "\r
     : "=a" (Result),          // %0\r
       "=m" (*Value)           // %1\r
     : "m"  (*Value)           // %2\r
diff --git a/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedDecrement.c b/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedDecrement.c
deleted file mode 100644 (file)
index 354a0e7..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/** @file\r
-  InterlockedDecrement function\r
-\r
-  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
-  This program and the accompanying materials\r
-  are licensed and made available under the terms and conditions of the BSD License\r
-  which accompanies this distribution.  The full text of the license may be found at\r
-  http://opensource.org/licenses/bsd-license.php.\r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-**/\r
-\r
-\r
-\r
-\r
-/**\r
-  Performs an atomic decrement of an 32-bit unsigned integer.\r
-\r
-  Performs an atomic decrement of the 32-bit unsigned integer specified by\r
-  Value and returns the decrement value. The decrement operation must be\r
-  performed using MP safe mechanisms. The state of the return value is not\r
-  guaranteed to be MP safe.\r
-\r
-  @param  Value A pointer to the 32-bit value to decrement.\r
-\r
-  @return The decrement value.\r
-\r
-**/\r
-UINT32\r
-EFIAPI\r
-InternalSyncDecrement (\r
-  IN      volatile UINT32           *Value\r
-  )\r
-{\r
-  _asm {\r
-    mov     eax, Value\r
-    lock    dec     dword ptr [eax]\r
-    mov     eax, [eax]\r
-  }\r
-}\r
index 4c460411867d37e0dd5339c24b30fb9270bd4b56..dd5a8de3ed7ebe62bcb1ee26b2b49a6d5a1e9f93 100644 (file)
@@ -1,6 +1,6 @@
 ;------------------------------------------------------------------------------\r
 ;\r
-; Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
+; Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
 ; This program and the accompanying materials\r
 ; are licensed and made available under the terms and conditions of the BSD License\r
 ; which accompanies this distribution.  The full text of the license may be found at\r
@@ -32,8 +32,8 @@
 ;------------------------------------------------------------------------------\r
 global ASM_PFX(InternalSyncDecrement)\r
 ASM_PFX(InternalSyncDecrement):\r
-    mov     eax, [esp + 4]\r
-    lock    dec     dword [eax]\r
-    mov     eax, [eax]\r
+    mov       ecx, [esp + 4]\r
+    mov       eax, 0FFFFFFFFh\r
+    lock xadd dword [ecx], eax\r
+    dec       eax\r
     ret\r
-\r
diff --git a/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedIncrement.c b/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedIncrement.c
deleted file mode 100644 (file)
index c61a550..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/** @file\r
-  InterLockedIncrement function\r
-\r
-  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
-  This program and the accompanying materials\r
-  are licensed and made available under the terms and conditions of the BSD License\r
-  which accompanies this distribution.  The full text of the license may be found at\r
-  http://opensource.org/licenses/bsd-license.php.\r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-**/\r
-\r
-\r
-\r
-\r
-/**\r
-  Performs an atomic increment of an 32-bit unsigned integer.\r
-\r
-  Performs an atomic increment of the 32-bit unsigned integer specified by\r
-  Value and returns the incremented value. The increment operation must be\r
-  performed using MP safe mechanisms. The state of the return value is not\r
-  guaranteed to be MP safe.\r
-\r
-  @param  Value A pointer to the 32-bit value to increment.\r
-\r
-  @return The incremented value.\r
-\r
-**/\r
-UINT32\r
-EFIAPI\r
-InternalSyncIncrement (\r
-  IN      volatile UINT32           *Value\r
-  )\r
-{\r
-  _asm {\r
-    mov     eax, Value\r
-    lock    inc     dword ptr [eax]\r
-    mov     eax, [eax]\r
-  }\r
-}\r
-\r
index 3902c732751e14b0da59401a2d1e670a6d10e5e8..0677e4bf78e64bb9c64dbefa5a6f51ea0a0481a5 100644 (file)
@@ -32,8 +32,9 @@
 ;------------------------------------------------------------------------------\r
 global ASM_PFX(InternalSyncIncrement)\r
 ASM_PFX(InternalSyncIncrement):\r
-    mov     eax, [esp + 4]\r
-    lock    inc     dword [eax]\r
-    mov     eax, [eax]\r
+    mov       ecx, [esp + 4]\r
+    mov       eax, 1\r
+    lock xadd dword [ecx], eax\r
+    inc       eax\r
     ret\r
 \r
diff --git a/MdePkg/Library/BaseSynchronizationLib/InterlockedDecrementMsc.c b/MdePkg/Library/BaseSynchronizationLib/InterlockedDecrementMsc.c
new file mode 100644 (file)
index 0000000..6dc9502
--- /dev/null
@@ -0,0 +1,46 @@
+/** @file\r
+  InterlockedDecrement function\r
+\r
+  Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+/**\r
+  Microsoft Visual Studio 7.1 Function Prototypes for I/O Intrinsics.\r
+**/\r
+\r
+long _InterlockedDecrement(\r
+   long * lpAddend\r
+);\r
+\r
+#pragma intrinsic(_InterlockedDecrement)\r
+\r
+/**\r
+  Performs an atomic decrement of an 32-bit unsigned integer.\r
+\r
+  Performs an atomic decrement of the 32-bit unsigned integer specified by\r
+  Value and returns the decrement value. The decrement operation must be\r
+  performed using MP safe mechanisms. The state of the return value is not\r
+  guaranteed to be MP safe.\r
+\r
+  @param  Value A pointer to the 32-bit value to decrement.\r
+\r
+  @return The decrement value.\r
+\r
+**/\r
+UINT32\r
+EFIAPI\r
+InternalSyncDecrement (\r
+  IN      volatile UINT32           *Value\r
+  )\r
+{\r
+  return _InterlockedDecrement ((long *)(Value));\r
+}\r
+\r
diff --git a/MdePkg/Library/BaseSynchronizationLib/InterlockedIncrementMsc.c b/MdePkg/Library/BaseSynchronizationLib/InterlockedIncrementMsc.c
new file mode 100644 (file)
index 0000000..8327d81
--- /dev/null
@@ -0,0 +1,46 @@
+/** @file\r
+  InterLockedIncrement function\r
+\r
+  Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+/**\r
+  Microsoft Visual Studio 7.1 Function Prototypes for I/O Intrinsics.\r
+**/\r
+\r
+long _InterlockedIncrement(\r
+   long * lpAddend\r
+);\r
+\r
+#pragma intrinsic(_InterlockedIncrement)\r
+\r
+/**\r
+  Performs an atomic increment of an 32-bit unsigned integer.\r
+\r
+  Performs an atomic increment of the 32-bit unsigned integer specified by\r
+  Value and returns the incremented value. The increment operation must be\r
+  performed using MP safe mechanisms. The state of the return value is not\r
+  guaranteed to be MP safe.\r
+\r
+  @param  Value A pointer to the 32-bit value to increment.\r
+\r
+  @return The incremented value.\r
+\r
+**/\r
+UINT32\r
+EFIAPI\r
+InternalSyncIncrement (\r
+  IN      volatile UINT32           *Value\r
+  )\r
+{\r
+  return _InterlockedIncrement ((long *)(Value));\r
+}\r
+\r
index 76c5a1275c222a150460847f39cb94276788fd26..0ab59ca70215d52d837236d319879c9a252e0a0d 100644 (file)
@@ -231,8 +231,7 @@ ReleaseSpinLock (
 \r
   Performs an atomic increment of the 32-bit unsigned integer specified by\r
   Value and returns the incremented value. The increment operation must be\r
-  performed using MP safe mechanisms. The state of the return value is not\r
-  guaranteed to be MP safe.\r
+  performed using MP safe mechanisms.\r
 \r
   If Value is NULL, then ASSERT().\r
 \r
@@ -256,8 +255,7 @@ InterlockedIncrement (
 \r
   Performs an atomic decrement of the 32-bit unsigned integer specified by\r
   Value and returns the decremented value. The decrement operation must be\r
-  performed using MP safe mechanisms. The state of the return value is not\r
-  guaranteed to be MP safe.\r
+  performed using MP safe mechanisms.\r
 \r
   If Value is NULL, then ASSERT().\r
 \r
index 5ac548b19feb5ce4edbd49a783da18af80efd88f..177739d3dab092d35a087c7a980c0ff01003e975 100644 (file)
@@ -247,8 +247,7 @@ ReleaseSpinLock (
 \r
   Performs an atomic increment of the 32-bit unsigned integer specified by\r
   Value and returns the incremented value. The increment operation must be\r
-  performed using MP safe mechanisms. The state of the return value is not\r
-  guaranteed to be MP safe.\r
+  performed using MP safe mechanisms.\r
 \r
   If Value is NULL, then ASSERT().\r
 \r
@@ -272,8 +271,7 @@ InterlockedIncrement (
 \r
   Performs an atomic decrement of the 32-bit unsigned integer specified by\r
   Value and returns the decremented value. The decrement operation must be\r
-  performed using MP safe mechanisms. The state of the return value is not\r
-  guaranteed to be MP safe.\r
+  performed using MP safe mechanisms.\r
 \r
   If Value is NULL, then ASSERT().\r
 \r
index e3298c8ab4ae0e8e1a5ef2b788b88cd06cd89246..6ab2d71870e967b29e5253ce564763a7140dec36 100644 (file)
@@ -249,8 +249,7 @@ ReleaseSpinLock (
 \r
   Performs an atomic increment of the 32-bit unsigned integer specified by\r
   Value and returns the incremented value. The increment operation must be\r
-  performed using MP safe mechanisms. The state of the return value is not\r
-  guaranteed to be MP safe.\r
+  performed using MP safe mechanisms.\r
 \r
   If Value is NULL, then ASSERT().\r
 \r
@@ -274,8 +273,7 @@ InterlockedIncrement (
 \r
   Performs an atomic decrement of the 32-bit unsigned integer specified by\r
   Value and returns the decremented value. The decrement operation must be\r
-  performed using MP safe mechanisms. The state of the return value is not\r
-  guaranteed to be MP safe.\r
+  performed using MP safe mechanisms.\r
 \r
   If Value is NULL, then ASSERT().\r
 \r
index 5224dd063ffda213b00d9a4cdfdd9dfaaef6b544..4c4d6e3fc7128f189faa9297e992c463ea416eb5 100644 (file)
 \r
 \r
 \r
-\r
 /**\r
   Performs an atomic increment of an 32-bit unsigned integer.\r
 \r
   Performs an atomic increment of the 32-bit unsigned integer specified by\r
   Value and returns the incremented value. The increment operation must be\r
-  performed using MP safe mechanisms. The state of the return value is not\r
-  guaranteed to be MP safe.\r
+  performed using MP safe mechanisms.\r
 \r
   @param  Value A pointer to the 32-bit value to increment.\r
 \r
@@ -38,9 +36,10 @@ InternalSyncIncrement (
   UINT32  Result;\r
 \r
   __asm__ __volatile__ (\r
+    "movl    $1, %%eax  \n\t"\r
     "lock               \n\t"\r
-    "incl    %2         \n\t"\r
-    "mov     %2, %%eax      "\r
+    "xadd    %%eax, %2  \n\t"\r
+    "inc     %%eax          "\r
     : "=a" (Result),          // %0\r
       "=m" (*Value)           // %1\r
     : "m"  (*Value)           // %2\r
@@ -57,8 +56,7 @@ InternalSyncIncrement (
 \r
   Performs an atomic decrement of the 32-bit unsigned integer specified by\r
   Value and returns the decremented value. The decrement operation must be\r
-  performed using MP safe mechanisms. The state of the return value is not\r
-  guaranteed to be MP safe.\r
+  performed using MP safe mechanisms.\r
 \r
   @param  Value A pointer to the 32-bit value to decrement.\r
 \r
@@ -74,9 +72,10 @@ InternalSyncDecrement (
    UINT32  Result;\r
 \r
   __asm__ __volatile__ (\r
-    "lock               \n\t"\r
-    "decl    %2         \n\t"\r
-    "mov     %2, %%eax      "\r
+    "movl    $-1, %%eax  \n\t"\r
+    "lock                \n\t"\r
+    "xadd    %%eax, %2   \n\t"\r
+    "dec     %%eax                  "\r
     : "=a" (Result),          // %0\r
       "=m" (*Value)           // %1\r
     : "m"  (*Value)           // %2\r
diff --git a/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedDecrement.c b/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedDecrement.c
deleted file mode 100644 (file)
index da402cd..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-/** @file\r
-  InterlockedDecrement function\r
-\r
-  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
-  This program and the accompanying materials\r
-  are licensed and made available under the terms and conditions of the BSD License\r
-  which accompanies this distribution.  The full text of the license may be found at\r
-  http://opensource.org/licenses/bsd-license.php.\r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-**/\r
-\r
-/**\r
-  Microsoft Visual Studio 7.1 Function Prototypes for I/O Intrinsics.\r
-**/\r
-\r
-long _InterlockedDecrement(\r
-   long * lpAddend\r
-);\r
-\r
-#pragma intrinsic(_InterlockedDecrement)\r
-\r
-/**\r
-  Performs an atomic decrement of an 32-bit unsigned integer.\r
-\r
-  Performs an atomic decrement of the 32-bit unsigned integer specified by\r
-  Value and returns the decrement value. The decrement operation must be\r
-  performed using MP safe mechanisms. The state of the return value is not\r
-  guaranteed to be MP safe.\r
-\r
-  @param  Value A pointer to the 32-bit value to decrement.\r
-\r
-  @return The decrement value.\r
-\r
-**/\r
-UINT32\r
-EFIAPI\r
-InternalSyncDecrement (\r
-  IN      volatile UINT32           *Value\r
-  )\r
-{\r
-  return _InterlockedDecrement ((long *)(UINTN)(Value));\r
-}\r
-\r
index 60f43111fe0e82db23b9c2136c9135c47a7de0b7..dabdca945eeaa821375da33856d54c98d0ebbb90 100644 (file)
@@ -1,6 +1,6 @@
 ;------------------------------------------------------------------------------\r
 ;\r
-; Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
+; Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
 ; This program and the accompanying materials\r
 ; are licensed and made available under the terms and conditions of the BSD License\r
 ; which accompanies this distribution.  The full text of the license may be found at\r
@@ -33,7 +33,7 @@
 ;------------------------------------------------------------------------------\r
 global ASM_PFX(InternalSyncDecrement)\r
 ASM_PFX(InternalSyncDecrement):\r
-    lock    dec     dword [rcx]\r
-    mov     eax, [rcx]\r
+    mov       eax, 0FFFFFFFFh\r
+    lock xadd dword [rcx], eax\r
+    dec       eax\r
     ret\r
-\r
diff --git a/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedIncrement.c b/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedIncrement.c
deleted file mode 100644 (file)
index bbd1384..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-/** @file\r
-  InterLockedIncrement function\r
-\r
-  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
-  This program and the accompanying materials\r
-  are licensed and made available under the terms and conditions of the BSD License\r
-  which accompanies this distribution.  The full text of the license may be found at\r
-  http://opensource.org/licenses/bsd-license.php.\r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-**/\r
-\r
-/**\r
-  Microsoft Visual Studio 7.1 Function Prototypes for I/O Intrinsics.\r
-**/\r
-\r
-long _InterlockedIncrement(\r
-   long * lpAddend\r
-);\r
-\r
-#pragma intrinsic(_InterlockedIncrement)\r
-\r
-/**\r
-  Performs an atomic increment of an 32-bit unsigned integer.\r
-\r
-  Performs an atomic increment of the 32-bit unsigned integer specified by\r
-  Value and returns the incremented value. The increment operation must be\r
-  performed using MP safe mechanisms. The state of the return value is not\r
-  guaranteed to be MP safe.\r
-\r
-  @param  Value A pointer to the 32-bit value to increment.\r
-\r
-  @return The incremented value.\r
-\r
-**/\r
-UINT32\r
-EFIAPI\r
-InternalSyncIncrement (\r
-  IN      volatile UINT32           *Value\r
-  )\r
-{\r
-  return _InterlockedIncrement ((long *)(UINTN)(Value));\r
-}\r
-\r
index 7f877b57740e2d9160a91c72606c1ef38f71e945..77379d998e220131e087ce844b17103c6826b8bd 100644 (file)
@@ -33,7 +33,8 @@
 ;------------------------------------------------------------------------------\r
 global ASM_PFX(InternalSyncIncrement)\r
 ASM_PFX(InternalSyncIncrement):\r
-    lock    inc     dword [rcx]\r
-    mov     eax, [rcx]\r
+    mov       eax, 1\r
+    lock xadd dword [rcx], eax\r
+    inc       eax\r
     ret\r
 \r