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