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