]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseSynchronizationLib/Arm/Synchronization.c
Clean up MdePkg source to correct some coding style issues, etc.
[mirror_edk2.git] / MdePkg / Library / BaseSynchronizationLib / Arm / Synchronization.c
1 /** @file
2 Implementation of synchronization functions. Still needs to be ported
3
4 Copyright (c) 2006 - 2010, Intel Corporation<BR>
5 Portions copyright (c) 2008-2009 Apple Inc. All rights reserved.<BR>
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 /**
17 Performs an atomic compare exchange operation on a 32-bit unsigned integer.
18
19 Performs an atomic compare exchange operation on the 32-bit unsigned integer
20 specified by Value. If Value is equal to CompareValue, then Value is set to
21 ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,
22 then Value is returned. The compare exchange operation must be performed using
23 MP safe mechanisms.
24
25 @param Value A pointer to the 32-bit value for the compare exchange
26 operation.
27 @param CompareValue 32-bit value used in compare operation.
28 @param ExchangeValue 32-bit value used in exchange operation.
29
30 @return The original *Value before exchange.
31
32 **/
33 UINT32
34 EFIAPI
35 InternalSyncCompareExchange32 (
36 IN volatile UINT32 *Value,
37 IN UINT32 CompareValue,
38 IN UINT32 ExchangeValue
39 )
40 {
41 return *Value != CompareValue ? *Value :
42 ((*Value = ExchangeValue), CompareValue);
43 }
44
45 /**
46 Performs an atomic compare exchange operation on a 64-bit unsigned integer.
47
48 Performs an atomic compare exchange operation on the 64-bit unsigned integer specified
49 by Value. If Value is equal to CompareValue, then Value is set to ExchangeValue and
50 CompareValue is returned. If Value is not equal to CompareValue, then Value is returned.
51 The compare exchange operation must be performed using MP safe mechanisms.
52
53 @param Value A pointer to the 64-bit value for the compare exchange
54 operation.
55 @param CompareValue 64-bit value used in compare operation.
56 @param ExchangeValue 64-bit value used in exchange operation.
57
58 @return The original *Value before exchange.
59
60 **/
61 UINT64
62 EFIAPI
63 InternalSyncCompareExchange64 (
64 IN volatile UINT64 *Value,
65 IN UINT64 CompareValue,
66 IN UINT64 ExchangeValue
67 )
68 {
69 return *Value != CompareValue ? *Value :
70 ((*Value = ExchangeValue), CompareValue);
71 }
72
73 /**
74 Performs an atomic increment of an 32-bit unsigned integer.
75
76 Performs an atomic increment of the 32-bit unsigned integer specified by
77 Value and returns the incremented value. The increment operation must be
78 performed using MP safe mechanisms. The state of the return value is not
79 guaranteed to be MP safe.
80
81 @param Value A pointer to the 32-bit value to increment.
82
83 @return The incremented value.
84
85 **/
86 UINT32
87 EFIAPI
88 InternalSyncIncrement (
89 IN volatile UINT32 *Value
90 )
91 {
92 return ++*Value;
93 }
94
95 /**
96 Performs an atomic decrement of an 32-bit unsigned integer.
97
98 Performs an atomic decrement of the 32-bit unsigned integer specified by
99 Value and returns the decrement value. The decrement operation must be
100 performed using MP safe mechanisms. The state of the return value is not
101 guaranteed to be MP safe.
102
103 @param Value A pointer to the 32-bit value to decrement.
104
105 @return The decrement value.
106
107 **/
108 UINT32
109 EFIAPI
110 InternalSyncDecrement (
111 IN volatile UINT32 *Value
112 )
113 {
114 return --*Value;
115 }