]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Foundation/Library/RuntimeDxe/EfiRuntimeLib/Ia32/Lock.c
Update the copyright notice format
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / RuntimeDxe / EfiRuntimeLib / Ia32 / 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.
19
20 --*/
21
22 #include "Tiano.h"
23 #include "EfiDriverLib.h"
24
25 extern
26 BOOLEAN
27 EfiAtRuntime (
28 VOID
29 );
30
31 VOID
32 EfiInitializeLock (
33 IN OUT EFI_LOCK *Lock,
34 IN EFI_TPL Priority
35 )
36 /*++
37
38 Routine Description:
39
40 Initialize a basic mutual exclusion lock. Each lock
41 provides mutual exclusion access at it's task priority
42 level. Since there is no-premption (at any TPL) or
43 multiprocessor support, acquiring the lock only consists
44 of raising to the locks TPL.
45
46 Note on a check build ASSERT()s are used to ensure proper
47 lock usage.
48
49 Arguments:
50
51 Lock - The EFI_LOCK structure to initialize
52
53 Priority - The task priority level of the lock
54
55
56 Returns:
57
58 An initialized Efi Lock structure.
59
60 --*/
61 {
62 Lock->Tpl = Priority;
63 Lock->OwnerTpl = 0;
64 Lock->Lock = 0;
65 }
66
67 EFI_STATUS
68 EfiAcquireLockOrFail (
69 IN EFI_LOCK *Lock
70 )
71 /*++
72
73 Routine Description:
74
75 Initialize a basic mutual exclusion lock. Each lock
76 provides mutual exclusion access at it's task priority
77 level. Since there is no-premption (at any TPL) or
78 multiprocessor support, acquiring the lock only consists
79 of raising to the locks TPL.
80
81 Arguments:
82
83 Lock - The EFI_LOCK structure to initialize
84
85 Returns:
86
87 EFI_SUCCESS - Lock Owned.
88 EFI_ACCESS_DENIED - Reentrant Lock Acquisition, Lock not Owned.
89
90 --*/
91 {
92 if (Lock->Lock != 0) {
93 //
94 // Lock is already owned, so bail out
95 //
96 return EFI_ACCESS_DENIED;
97 }
98
99 if (!EfiAtRuntime ()) {
100 //
101 // The check is just debug code for core inplementation. It must
102 // always be true in a driver
103 //
104 Lock->OwnerTpl = gBS->RaiseTPL (Lock->Tpl);
105 }
106
107 Lock->Lock += 1;
108 return EFI_SUCCESS;
109 }
110
111 VOID
112 EfiAcquireLock (
113 IN EFI_LOCK *Lock
114 )
115 /*++
116
117 Routine Description:
118
119 Raising to the task priority level of the mutual exclusion
120 lock, and then acquires ownership of the lock.
121
122 Arguments:
123
124 Lock - The lock to acquire
125
126 Returns:
127
128 Lock owned
129
130 --*/
131 {
132 EFI_STATUS Status;
133
134 Status = EfiAcquireLockOrFail (Lock);
135
136 //
137 // Lock was already locked.
138 //
139 ASSERT_EFI_ERROR (Status);
140 }
141
142 VOID
143 EfiReleaseLock (
144 IN EFI_LOCK *Lock
145 )
146 /*++
147
148 Routine Description:
149
150 Releases ownership of the mutual exclusion lock, and
151 restores the previous task priority level.
152
153 Arguments:
154
155 Lock - The lock to release
156
157 Returns:
158
159 Lock unowned
160
161 --*/
162 {
163 EFI_TPL Tpl;
164
165 Tpl = Lock->OwnerTpl;
166
167 ASSERT (Lock->Lock == 1);
168 Lock->Lock -= 1;
169
170 if (!EfiAtRuntime ()) {
171 //
172 // The check is just debug code for core inplementation. It must
173 // always be true in a driver
174 //
175 gBS->RestoreTPL (Tpl);
176 }
177 }