]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseSynchronizationLib/Ebc/Synchronization.c
MdePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdePkg / Library / BaseSynchronizationLib / Ebc / Synchronization.c
1 /** @file
2 Implementation of synchronization functions on EBC.
3
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 /**
10 Performs an atomic compare exchange operation on a 16-bit
11 unsigned integer.
12
13 Performs an atomic compare exchange operation on the 16-bit
14 unsigned integer specified by Value. If Value is equal to
15 CompareValue, then Value is set to ExchangeValue and
16 CompareValue is returned. If Value is not equal to
17 CompareValue, then Value is returned. The compare exchange
18 operation must be performed using MP safe mechanisms.
19
20 @param Value A pointer to the 16-bit value for the
21 compare exchange operation.
22 @param CompareValue 16-bit value used in compare operation.
23 @param ExchangeValue 16-bit value used in exchange operation.
24
25 @return The original *Value before exchange.
26
27 **/
28 UINT16
29 EFIAPI
30 InternalSyncCompareExchange16 (
31 IN volatile UINT16 *Value,
32 IN UINT16 CompareValue,
33 IN UINT16 ExchangeValue
34 )
35 {
36 return *Value != CompareValue ? *Value :
37 ((*Value = ExchangeValue), CompareValue);
38 }
39
40 /**
41 Performs an atomic compare exchange operation on a 32-bit
42 unsigned integer.
43
44 Performs an atomic compare exchange operation on the 32-bit
45 unsigned integer specified by Value. If Value is equal to
46 CompareValue, then Value is set to ExchangeValue and
47 CompareValue is returned. If Value is not equal to
48 CompareValue, then Value is returned. The compare exchange
49 operation must be performed using MP safe mechanisms.
50
51 @param Value A pointer to the 32-bit value for the
52 compare exchange operation.
53 @param CompareValue 32-bit value used in compare operation.
54 @param ExchangeValue 32-bit value used in exchange operation.
55
56 @return The original *Value before exchange.
57
58 **/
59 UINT32
60 EFIAPI
61 InternalSyncCompareExchange32 (
62 IN volatile UINT32 *Value,
63 IN UINT32 CompareValue,
64 IN UINT32 ExchangeValue
65 )
66 {
67 return *Value != CompareValue ? *Value :
68 ((*Value = ExchangeValue), CompareValue);
69 }
70
71 /**
72 Performs an atomic compare exchange operation on a 64-bit unsigned integer.
73
74 Performs an atomic compare exchange operation on the 64-bit unsigned integer specified
75 by Value. If Value is equal to CompareValue, then Value is set to ExchangeValue and
76 CompareValue is returned. If Value is not equal to CompareValue, then Value is returned.
77 The compare exchange operation must be performed using MP safe mechanisms.
78
79 @param Value A pointer to the 64-bit value for the compare exchange
80 operation.
81 @param CompareValue 64-bit value used in compare operation.
82 @param ExchangeValue 64-bit value used in exchange operation.
83
84 @return The original *Value before exchange.
85
86 **/
87 UINT64
88 EFIAPI
89 InternalSyncCompareExchange64 (
90 IN volatile UINT64 *Value,
91 IN UINT64 CompareValue,
92 IN UINT64 ExchangeValue
93 )
94 {
95 return *Value != CompareValue ? *Value :
96 ((*Value = ExchangeValue), CompareValue);
97 }
98
99 /**
100 Performs an atomic increment of an 32-bit unsigned integer.
101
102 Performs an atomic increment of the 32-bit unsigned integer specified by
103 Value and returns the incremented value. The increment operation must be
104 performed using MP safe mechanisms. The state of the return value is not
105 guaranteed to be MP safe.
106
107 @param Value A pointer to the 32-bit value to increment.
108
109 @return The incremented value.
110
111 **/
112 UINT32
113 EFIAPI
114 InternalSyncIncrement (
115 IN volatile UINT32 *Value
116 )
117 {
118 return ++*Value;
119 }
120
121 /**
122 Performs an atomic decrement of an 32-bit unsigned integer.
123
124 Performs an atomic decrement of the 32-bit unsigned integer specified by
125 Value and returns the decrement value. The decrement operation must be
126 performed using MP safe mechanisms. The state of the return value is not
127 guaranteed to be MP safe.
128
129 @param Value A pointer to the 32-bit value to decrement.
130
131 @return The decrement value.
132
133 **/
134 UINT32
135 EFIAPI
136 InternalSyncDecrement (
137 IN volatile UINT32 *Value
138 )
139 {
140 return --*Value;
141 }