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