1 /** @file 2 Implementation of synchronization functions on EBC. 3 4 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR> 5 This program and the accompanying materials 6 are licensed and made available under the terms and conditions of the BSD License 7 which accompanies this distribution. The full text of the license may be found at 8 http://opensource.org/licenses/bsd-license.php. 9 10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 12 13 **/ 14 15 /** 16 Performs an atomic compare exchange operation on a 16-bit 17 unsigned integer. 18 19 Performs an atomic compare exchange operation on the 16-bit 20 unsigned integer specified by Value. If Value is equal to 21 CompareValue, then Value is set to ExchangeValue and 22 CompareValue is returned. If Value is not equal to 23 CompareValue, then Value is returned. The compare exchange 24 operation must be performed using MP safe mechanisms. 25 26 @param Value A pointer to the 16-bit value for the 27 compare exchange operation. 28 @param CompareValue 16-bit value used in compare operation. 29 @param ExchangeValue 16-bit value used in exchange operation. 30 31 @return The original *Value before exchange. 32 33 **/ 34 UINT16 35 EFIAPI 36 InternalSyncCompareExchange16 ( 37 IN volatile UINT16 *Value, 38 IN UINT16 CompareValue, 39 IN UINT16 ExchangeValue 40 ) 41 { 42 return *Value != CompareValue ? *Value : 43 ((*Value = ExchangeValue), CompareValue); 44 } 45 46 /** 47 Performs an atomic compare exchange operation on a 32-bit 48 unsigned integer. 49 50 Performs an atomic compare exchange operation on the 32-bit 51 unsigned integer specified by Value. If Value is equal to 52 CompareValue, then Value is set to ExchangeValue and 53 CompareValue is returned. If Value is not equal to 54 CompareValue, then Value is returned. The compare exchange 55 operation must be performed using MP safe mechanisms. 56 57 @param Value A pointer to the 32-bit value for the 58 compare exchange operation. 59 @param CompareValue 32-bit value used in compare operation. 60 @param ExchangeValue 32-bit value used in exchange operation. 61 62 @return The original *Value before exchange. 63 64 **/ 65 UINT32 66 EFIAPI 67 InternalSyncCompareExchange32 ( 68 IN volatile UINT32 *Value, 69 IN UINT32 CompareValue, 70 IN UINT32 ExchangeValue 71 ) 72 { 73 return *Value != CompareValue ? *Value : 74 ((*Value = ExchangeValue), CompareValue); 75 } 76 77 /** 78 Performs an atomic compare exchange operation on a 64-bit unsigned integer. 79 80 Performs an atomic compare exchange operation on the 64-bit unsigned integer specified 81 by Value. If Value is equal to CompareValue, then Value is set to ExchangeValue and 82 CompareValue is returned. If Value is not equal to CompareValue, then Value is returned. 83 The compare exchange operation must be performed using MP safe mechanisms. 84 85 @param Value A pointer to the 64-bit value for the compare exchange 86 operation. 87 @param CompareValue 64-bit value used in compare operation. 88 @param ExchangeValue 64-bit value used in exchange operation. 89 90 @return The original *Value before exchange. 91 92 **/ 93 UINT64 94 EFIAPI 95 InternalSyncCompareExchange64 ( 96 IN volatile UINT64 *Value, 97 IN UINT64 CompareValue, 98 IN UINT64 ExchangeValue 99 ) 100 { 101 return *Value != CompareValue ? *Value : 102 ((*Value = ExchangeValue), CompareValue); 103 } 104 105 /** 106 Performs an atomic increment of an 32-bit unsigned integer. 107 108 Performs an atomic increment of the 32-bit unsigned integer specified by 109 Value and returns the incremented value. The increment operation must be 110 performed using MP safe mechanisms. The state of the return value is not 111 guaranteed to be MP safe. 112 113 @param Value A pointer to the 32-bit value to increment. 114 115 @return The incremented value. 116 117 **/ 118 UINT32 119 EFIAPI 120 InternalSyncIncrement ( 121 IN volatile UINT32 *Value 122 ) 123 { 124 return ++*Value; 125 } 126 127 /** 128 Performs an atomic decrement of an 32-bit unsigned integer. 129 130 Performs an atomic decrement of the 32-bit unsigned integer specified by 131 Value and returns the decrement value. The decrement operation must be 132 performed using MP safe mechanisms. The state of the return value is not 133 guaranteed to be MP safe. 134 135 @param Value A pointer to the 32-bit value to decrement. 136 137 @return The decrement value. 138 139 **/ 140 UINT32 141 EFIAPI 142 InternalSyncDecrement ( 143 IN volatile UINT32 *Value 144 ) 145 { 146 return --*Value; 147 } 148