]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Core/Dxe/Library/Library.c
MdeModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / Library / Library.c
CommitLineData
162ed594 1/** @file\r
797a9d67 2 DXE Core library services.\r
23c98c94 3\r
cd5ebaa0 4Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>\r
9d510e61 5SPDX-License-Identifier: BSD-2-Clause-Patent\r
28a00297 6\r
797a9d67 7**/\r
28a00297 8\r
9c4ac31c 9#include "DxeMain.h"\r
28a00297 10\r
28a00297 11//\r
12// Lock Stuff\r
13//\r
162ed594 14/**\r
28a00297 15 Initialize a basic mutual exclusion lock. Each lock\r
16 provides mutual exclusion access at it's task priority\r
17 level. Since there is no-premption (at any TPL) or\r
18 multiprocessor support, acquiring the lock only consists\r
19 of raising to the locks TPL.\r
20\r
022c6d45 21 @param Lock The EFI_LOCK structure to initialize\r
28a00297 22\r
022c6d45 23 @retval EFI_SUCCESS Lock Owned.\r
162ed594 24 @retval EFI_ACCESS_DENIED Reentrant Lock Acquisition, Lock not Owned.\r
28a00297 25\r
162ed594 26**/\r
27EFI_STATUS\r
28CoreAcquireLockOrFail (\r
29 IN EFI_LOCK *Lock\r
30 )\r
28a00297 31{\r
32 ASSERT (Lock != NULL);\r
33 ASSERT (Lock->Lock != EfiLockUninitialized);\r
34\r
35 if (Lock->Lock == EfiLockAcquired) {\r
36 //\r
37 // Lock is already owned, so bail out\r
38 //\r
39 return EFI_ACCESS_DENIED;\r
40 }\r
41\r
42 Lock->OwnerTpl = CoreRaiseTpl (Lock->Tpl);\r
43\r
44 Lock->Lock = EfiLockAcquired;\r
45 return EFI_SUCCESS;\r
46}\r
47\r
48\r
28a00297 49\r
162ed594 50/**\r
28a00297 51 Raising to the task priority level of the mutual exclusion\r
52 lock, and then acquires ownership of the lock.\r
53\r
022c6d45 54 @param Lock The lock to acquire\r
28a00297 55\r
162ed594 56 @return Lock owned\r
28a00297 57\r
162ed594 58**/\r
59VOID\r
60CoreAcquireLock (\r
61 IN EFI_LOCK *Lock\r
62 )\r
28a00297 63{\r
64 ASSERT (Lock != NULL);\r
65 ASSERT (Lock->Lock == EfiLockReleased);\r
66\r
67 Lock->OwnerTpl = CoreRaiseTpl (Lock->Tpl);\r
68 Lock->Lock = EfiLockAcquired;\r
69}\r
70\r
71\r
28a00297 72\r
162ed594 73/**\r
74 Releases ownership of the mutual exclusion lock, and\r
75 restores the previous task priority level.\r
28a00297 76\r
022c6d45 77 @param Lock The lock to release\r
28a00297 78\r
162ed594 79 @return Lock unowned\r
28a00297 80\r
162ed594 81**/\r
82VOID\r
83CoreReleaseLock (\r
84 IN EFI_LOCK *Lock\r
85 )\r
28a00297 86{\r
87 EFI_TPL Tpl;\r
88\r
89 ASSERT (Lock != NULL);\r
90 ASSERT (Lock->Lock == EfiLockAcquired);\r
91\r
92 Tpl = Lock->OwnerTpl;\r
93\r
94 Lock->Lock = EfiLockReleased;\r
95\r
96 CoreRestoreTpl (Tpl);\r
97}\r
98\r
99\r
162ed594 100\r