]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/BaseSynchronizationLib/Ebc/Synchronization.c
MdePkg/BaseSynchronizationLib: Add InterlockedCompareExchange16
[mirror_edk2.git] / MdePkg / Library / BaseSynchronizationLib / Ebc / Synchronization.c
index 9c34b9f128eda761fae8801d7b7ae438671f5a49..a57860203b120268898c085770a60e489d699fe4 100644 (file)
 \r
 **/\r
 \r
+/**\r
+  Performs an atomic compare exchange operation on a 16-bit\r
+  unsigned integer.\r
+\r
+  Performs an atomic compare exchange operation on the 16-bit\r
+  unsigned integer specified by Value.  If Value is equal to\r
+  CompareValue, then Value is set to ExchangeValue and\r
+  CompareValue is returned.  If Value is not equal to\r
+  CompareValue, then Value is returned. The compare exchange\r
+  operation must be performed using MP safe mechanisms.\r
+\r
+  @param  Value         A pointer to the 16-bit value for the\r
+                        compare exchange operation.\r
+  @param  CompareValue  16-bit value used in compare operation.\r
+  @param  ExchangeValue 16-bit value used in exchange operation.\r
+\r
+  @return The original *Value before exchange.\r
+\r
+**/\r
+UINT16\r
+EFIAPI\r
+InternalSyncCompareExchange16 (\r
+  IN      volatile UINT16           *Value,\r
+  IN      UINT16                    CompareValue,\r
+  IN      UINT16                    ExchangeValue\r
+  )\r
+{\r
+  return *Value != CompareValue ? *Value :\r
+           ((*Value = ExchangeValue), CompareValue);\r
+}\r
+\r
 /**\r
   Performs an atomic compare exchange operation on a 32-bit\r
   unsigned integer.\r