]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Foundation/Library/RuntimeDxe/EfiRuntimeLib/Ipf/Lock.c
Update the copyright notice format
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / RuntimeDxe / EfiRuntimeLib / Ipf / Lock.c
1 /*++
2
3 Copyright (c) 2004, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 Lock.c
15
16 Abstract:
17
18 Support for locking lib services. These primitives may be implemented
19 as Esal calls but since these result in small code that us position
20 independent, we can use lib functions. ESAL calls have a significant
21 software overhead and too deep nesting is bad for the stack.
22
23 --*/
24
25 #include "Tiano.h"
26 #include "EfiDriverLib.h"
27
28 extern
29 BOOLEAN
30 EfiAtRuntime (
31 VOID
32 );
33
34 VOID
35 EfiInitializeLock (
36 IN OUT EFI_LOCK *Lock,
37 IN EFI_TPL Priority
38 )
39 /*++
40
41 Routine Description:
42
43 Initialize a basic mutual exclusion lock. There is
44 no concept of TPL at runtime hence priority is
45 ignored.
46
47 Arguments:
48
49 Lock - The EFI_LOCK structure to initialize
50
51 Priority - Ignored
52
53
54 Returns:
55
56 An initialized Efi Lock structure.
57
58 --*/
59 {
60 Lock->Tpl = Priority;
61 Lock->OwnerTpl = 0;
62 Lock->Lock = 0;
63 }
64
65 EFI_STATUS
66 EfiAcquireLockOrFail (
67 IN EFI_LOCK *Lock
68 )
69 /*++
70
71 Routine Description:
72
73 Initialize a basic mutual exclusion lock. For now,
74 only allow one level of nesting.
75
76 Arguments:
77
78 Lock - The EFI_LOCK structure to initialize
79
80 Returns:
81
82 EFI_SUCCESS - Lock Owned.
83 EFI_ACCESS_DENIED - Reentrant Lock Acquisition, Lock not Owned.
84
85 --*/
86 {
87 if (Lock->Lock != 0) {
88 //
89 // Lock is already owned, so bail out
90 //
91 return EFI_ACCESS_DENIED;
92 }
93
94 if (!EfiAtRuntime ()) {
95 //
96 // The check is just debug code for core inplementation. It must
97 // always be true in a driver
98 //
99 Lock->OwnerTpl = gBS->RaiseTPL (Lock->Tpl);
100 }
101
102 Lock->Lock += 1;
103 return EFI_SUCCESS;
104 }
105
106 VOID
107 EfiAcquireLock (
108 IN EFI_LOCK *Lock
109 )
110 /*++
111
112 Routine Description:
113
114 Acquires ownership of the lock.
115
116 Arguments:
117
118 Lock - The lock to acquire
119
120 Returns:
121
122 Lock owned
123
124 --*/
125 {
126 EFI_STATUS Status;
127
128 Status = EfiAcquireLockOrFail (Lock);
129
130 //
131 // Lock was already locked.
132 //
133 ASSERT_EFI_ERROR (Status);
134 }
135
136 VOID
137 EfiReleaseLock (
138 IN EFI_LOCK *Lock
139 )
140 /*++
141
142 Routine Description:
143
144 Releases ownership of the mutual exclusion lock.
145
146 Arguments:
147
148 Lock - The lock to release
149
150 Returns:
151
152 Lock unowned
153
154 --*/
155 {
156 EFI_TPL Tpl;
157
158 Tpl = Lock->OwnerTpl;
159
160 ASSERT (Lock->Lock == 1);
161 Lock->Lock -= 1;
162
163 if (!EfiAtRuntime ()) {
164 //
165 // The check is just debug code for core inplementation. It must
166 // always be true in a driver
167 //
168 gBS->RestoreTPL (Tpl);
169 }
170 }