]>
git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Foundation/Library/RuntimeDxe/EfiRuntimeLib/Ipf/Lock.c
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
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.
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.
26 #include "EfiDriverLib.h"
36 IN OUT EFI_LOCK
*Lock
,
43 Initialize a basic mutual exclusion lock. There is
44 no concept of TPL at runtime hence priority is
49 Lock - The EFI_LOCK structure to initialize
56 An initialized Efi Lock structure.
66 EfiAcquireLockOrFail (
73 Initialize a basic mutual exclusion lock. For now,
74 only allow one level of nesting.
78 Lock - The EFI_LOCK structure to initialize
82 EFI_SUCCESS - Lock Owned.
83 EFI_ACCESS_DENIED - Reentrant Lock Acquisition, Lock not Owned.
87 if (Lock
->Lock
!= 0) {
89 // Lock is already owned, so bail out
91 return EFI_ACCESS_DENIED
;
94 if (!EfiAtRuntime ()) {
96 // The check is just debug code for core inplementation. It must
97 // always be true in a driver
99 Lock
->OwnerTpl
= gBS
->RaiseTPL (Lock
->Tpl
);
114 Acquires ownership of the lock.
118 Lock - The lock to acquire
128 Status
= EfiAcquireLockOrFail (Lock
);
131 // Lock was already locked.
133 ASSERT_EFI_ERROR (Status
);
144 Releases ownership of the mutual exclusion lock.
148 Lock - The lock to release
158 Tpl
= Lock
->OwnerTpl
;
160 ASSERT (Lock
->Lock
== 1);
163 if (!EfiAtRuntime ()) {
165 // The check is just debug code for core inplementation. It must
166 // always be true in a driver
168 gBS
->RestoreTPL (Tpl
);