]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/BaseLib/Synchronization.c
Add comments on the definition of SPIN_LOCK_RELEASED & SPIN_LOCK_ACQUIRED
[mirror_edk2.git] / MdePkg / Library / BaseLib / Synchronization.c
index 4c4734523d4a88f665499f8a6d634a61f8c3d37f..59919a7f03b1ac1955d1075fd30585d060e10c94 100644 (file)
 \r
 **/\r
 \r
-#define SPIN_LOCK_RELEASED          ((SPIN_LOCK)1)\r
-#define SPIN_LOCK_ACQUIRED          ((SPIN_LOCK)2)\r
+#include "BaseLibInternals.h"\r
 \r
-UINT32\r
-EFIAPI\r
-InternalSyncIncrement (\r
-  IN      volatile UINT32           *Value\r
-  );\r
-\r
-UINT32\r
-EFIAPI\r
-InternalSyncDecrement (\r
-  IN      volatile UINT32           *Value\r
-  );\r
-\r
-UINT32\r
-EFIAPI\r
-InternalSyncCompareExchange32 (\r
-  IN      volatile UINT32           *Value,\r
-  IN      UINT32                    CompareValue,\r
-  IN      UINT32                    ExchangeValue\r
-  );\r
-\r
-UINT64\r
-EFIAPI\r
-InternalSyncCompareExchange64 (\r
-  IN      volatile UINT64           *Value,\r
-  IN      UINT64                    CompareValue,\r
-  IN      UINT64                    ExchangeValue\r
-  );\r
+//\r
+// SPIN_LOCK_RELEASED & SPIN_LOCK_ACQUIRED should belong to type "SPIN_LOCK".\r
+// Here we use type-case "UINTN" to avoid "volatile" modifier on const integers.\r
+//\r
+#define SPIN_LOCK_RELEASED          ((UINTN) 1)\r
+#define SPIN_LOCK_ACQUIRED          ((UINTN) 2)\r
 \r
 /**\r
   Retrieves the architecture specific spin lock alignment requirements for\r
@@ -131,12 +109,12 @@ AcquireSpinLock (
   Tick = 0;\r
   Start = 0;\r
   End = 0;\r
-  if (FixedPcdGet32 (PcdSpinLockTimeout) > 0) {\r
+  if (PcdGet32 (PcdSpinLockTimeout) > 0) {\r
     Tick = GetPerformanceCounter ();\r
     Timeout = DivU64x32 (\r
                 MultU64x32 (\r
                   GetPerformanceCounterProperties (&Start, &End),\r
-                  FixedPcdGet32 (PcdSpinLockTimeout)\r
+                  PcdGet32 (PcdSpinLockTimeout)\r
                   ),\r
                 1000000\r
                 );\r
@@ -177,8 +155,13 @@ AcquireSpinLockOrFail (
   IN OUT  SPIN_LOCK                 *SpinLock\r
   )\r
 {\r
+  SPIN_LOCK    LockValue;\r
+\r
   ASSERT (SpinLock != NULL);\r
-  ASSERT (*SpinLock == SPIN_LOCK_ACQUIRED || *SpinLock == SPIN_LOCK_RELEASED);\r
+\r
+  LockValue = *SpinLock;\r
+  ASSERT (LockValue == SPIN_LOCK_ACQUIRED || LockValue == SPIN_LOCK_RELEASED);\r
+\r
   return (BOOLEAN)(\r
            InterlockedCompareExchangePointer (\r
              (VOID**)SpinLock,\r
@@ -208,8 +191,13 @@ ReleaseSpinLock (
   IN OUT  SPIN_LOCK                 *SpinLock\r
   )\r
 {\r
+  SPIN_LOCK    LockValue;\r
+\r
   ASSERT (SpinLock != NULL);\r
-  ASSERT (*SpinLock == SPIN_LOCK_ACQUIRED || *SpinLock == SPIN_LOCK_RELEASED);\r
+\r
+  LockValue = *SpinLock;\r
+  ASSERT (LockValue == SPIN_LOCK_ACQUIRED || LockValue == SPIN_LOCK_RELEASED);\r
+\r
   *SpinLock = SPIN_LOCK_RELEASED;\r
   return SpinLock;\r
 }\r
@@ -267,6 +255,14 @@ InterlockedDecrement (
 /**\r
   Performs an atomic compare exchange operation on a 32-bit unsigned integer.\r
 \r
+  Performs an atomic compare exchange operation on the 32-bit unsigned integer\r
+  specified by Value.  If Value is equal to CompareValue, then Value is set to \r
+  ExchangeValue and CompareValue is returned.  If Value is not equal to CompareValue,\r
+  then Value is returned.  The compare exchange operation must be performed using \r
+  MP safe mechanisms.\r
+\r
+  If Value is NULL, then ASSERT().\r
+\r
   @param  Value         A pointer to the 32-bit value for the compare exchange\r
                         operation.\r
   @param  CompareValue  32-bit value used in compare operation.\r
@@ -290,6 +286,13 @@ InterlockedCompareExchange32 (
 /**\r
   Performs an atomic compare exchange operation on a 64-bit unsigned integer.\r
 \r
+  Performs an atomic compare exchange operation on the 64-bit unsigned integer specified \r
+  by Value.  If Value is equal to CompareValue, then Value is set to ExchangeValue and \r
+  CompareValue is returned.  If Value is not equal to CompareValue, then Value is returned. \r
+  The compare exchange operation must be performed using MP safe mechanisms.\r
+\r
+  If Value is NULL, then ASSERT().\r
+\r
   @param  Value         A pointer to the 64-bit value for the compare exchange\r
                         operation.\r
   @param  CompareValue  64-bit value used in compare operation.\r
@@ -335,7 +338,11 @@ InterlockedCompareExchangePointer (
   IN      VOID                      *ExchangeValue\r
   )\r
 {\r
-  switch (sizeof (*Value)) {\r
+  UINT8  SizeOfValue;\r
+\r
+  SizeOfValue = sizeof (*Value);\r
+\r
+  switch (SizeOfValue) {\r
     case sizeof (UINT32):\r
       return (VOID*)(UINTN)InterlockedCompareExchange32 (\r
                              (UINT32*)Value,\r