]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/BaseLib/Synchronization.c
1. added functions header for BaseUefiDecompressLi
[mirror_edk2.git] / MdePkg / Library / BaseLib / Synchronization.c
index df395869a295a1b8f0675caaf5624e3b55152ef0..cf001ce4d155ebd66d832eef9ec520db6503faaa 100644 (file)
 \r
 **/\r
 \r
-#define SPIN_LOCK_RELEASED          ((SPIN_LOCK)0)\r
-#define SPIN_LOCK_ACQUIRED          ((SPIN_LOCK)-1)\r
+#define SPIN_LOCK_RELEASED          ((SPIN_LOCK)1)\r
+#define SPIN_LOCK_ACQUIRED          ((SPIN_LOCK)2)\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
+/**\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
+/**\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
+  @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
+  @param  ExchangeValue 32-bit value used in exchange operation.\r
+\r
+  @return The original *Value before exchange.\r
+\r
+**/\r
 UINT32\r
 EFIAPI\r
 InternalSyncCompareExchange32 (\r
@@ -37,6 +80,22 @@ InternalSyncCompareExchange32 (
   IN      UINT32                    ExchangeValue\r
   );\r
 \r
+/**\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
+  @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
+  @param  ExchangeValue 64-bit value used in exchange operation.\r
+\r
+  @return The original *Value before exchange.\r
+\r
+**/\r
 UINT64\r
 EFIAPI\r
 InternalSyncCompareExchange64 (\r
@@ -94,7 +153,7 @@ InitializeSpinLock (
   )\r
 {\r
   ASSERT (SpinLock != NULL);\r
-  *SpinLock = 0;\r
+  *SpinLock = SPIN_LOCK_RELEASED;\r
   return SpinLock;\r
 }\r
 \r
@@ -131,12 +190,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
@@ -178,6 +237,7 @@ AcquireSpinLockOrFail (
   )\r
 {\r
   ASSERT (SpinLock != NULL);\r
+  ASSERT (*SpinLock == SPIN_LOCK_ACQUIRED || *SpinLock == SPIN_LOCK_RELEASED);\r
   return (BOOLEAN)(\r
            InterlockedCompareExchangePointer (\r
              (VOID**)SpinLock,\r
@@ -208,7 +268,8 @@ ReleaseSpinLock (
   )\r
 {\r
   ASSERT (SpinLock != NULL);\r
-  *SpinLock = 0;\r
+  ASSERT (*SpinLock == SPIN_LOCK_ACQUIRED || *SpinLock == SPIN_LOCK_RELEASED);\r
+  *SpinLock = SPIN_LOCK_RELEASED;\r
   return SpinLock;\r
 }\r
 \r
@@ -265,6 +326,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
@@ -276,7 +345,7 @@ InterlockedDecrement (
 UINT32\r
 EFIAPI\r
 InterlockedCompareExchange32 (\r
-  IN      UINT32                    *Value,\r
+  IN OUT  UINT32                    *Value,\r
   IN      UINT32                    CompareValue,\r
   IN      UINT32                    ExchangeValue\r
   )\r
@@ -288,6 +357,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
@@ -299,7 +375,7 @@ InterlockedCompareExchange32 (
 UINT64\r
 EFIAPI\r
 InterlockedCompareExchange64 (\r
-  IN      UINT64                    *Value,\r
+  IN OUT  UINT64                    *Value,\r
   IN      UINT64                    CompareValue,\r
   IN      UINT64                    ExchangeValue\r
   )\r
@@ -328,7 +404,7 @@ InterlockedCompareExchange64 (
 VOID *\r
 EFIAPI\r
 InterlockedCompareExchangePointer (\r
-  IN      VOID                      **Value,\r
+  IN OUT  VOID                      **Value,\r
   IN      VOID                      *CompareValue,\r
   IN      VOID                      *ExchangeValue\r
   )\r