]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseSynchronizationLib/Arm/Synchronization.c
e046e1b373c55649a3a882b53bb92df9214be2da
[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 - 2009, 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 UINT32
17 EFIAPI
18 InternalSyncCompareExchange32 (
19 IN volatile UINT32 *Value,
20 IN UINT32 CompareValue,
21 IN UINT32 ExchangeValue
22 )
23 {
24 return *Value != CompareValue ? *Value :
25 ((*Value = ExchangeValue), CompareValue);
26 }
27
28 /**
29 Performs an atomic compare exchange operation on a 64-bit unsigned integer.
30
31 Performs an atomic compare exchange operation on the 64-bit unsigned integer specified
32 by Value. If Value is equal to CompareValue, then Value is set to ExchangeValue and
33 CompareValue is returned. If Value is not equal to CompareValue, then Value is returned.
34 The compare exchange operation must be performed using MP safe mechanisms.
35
36 @param Value A pointer to the 64-bit value for the compare exchange
37 operation.
38 @param CompareValue 64-bit value used in compare operation.
39 @param ExchangeValue 64-bit value used in exchange operation.
40
41 @return The original *Value before exchange.
42
43 **/
44 UINT64
45 EFIAPI
46 InternalSyncCompareExchange64 (
47 IN volatile UINT64 *Value,
48 IN UINT64 CompareValue,
49 IN UINT64 ExchangeValue
50 )
51 {
52 return *Value != CompareValue ? *Value :
53 ((*Value = ExchangeValue), CompareValue);
54 }
55
56 /**
57 Performs an atomic increment of an 32-bit unsigned integer.
58
59 Performs an atomic increment of the 32-bit unsigned integer specified by
60 Value and returns the incremented value. The increment operation must be
61 performed using MP safe mechanisms. The state of the return value is not
62 guaranteed to be MP safe.
63
64 @param Value A pointer to the 32-bit value to increment.
65
66 @return The incremented value.
67
68 **/
69 UINT32
70 EFIAPI
71 InternalSyncIncrement (
72 IN volatile UINT32 *Value
73 )
74 {
75 return ++*Value;
76 }
77
78 /**
79 Performs an atomic decrement of an 32-bit unsigned integer.
80
81 Performs an atomic decrement of the 32-bit unsigned integer specified by
82 Value and returns the decrement value. The decrement operation must be
83 performed using MP safe mechanisms. The state of the return value is not
84 guaranteed to be MP safe.
85
86 @param Value A pointer to the 32-bit value to decrement.
87
88 @return The decrement value.
89
90 **/
91 UINT32
92 EFIAPI
93 InternalSyncDecrement (
94 IN volatile UINT32 *Value
95 )
96 {
97 return --*Value;
98 }