1/*++
2
3Copyright (c) 1998  Intel Corporation
4
5Module Name:
6
7    lock.c
8
9Abstract:
10
11    Implements FLOCK
12
13
14
15Revision History
16
17--*/
18
19
20#include "lib.h"
21
22
23
24#ifndef __GNUC__
25#pragma RUNTIME_CODE(RtAcquireLock)
26#endif
27VOID
28RtAcquireLock (
29    IN FLOCK    *Lock
30    )
31/*++
32
33Routine Description:
34
35    Raising to the task priority level of the mutual exclusion
36    lock, and then acquires ownership of the lock.
37
38Arguments:
39
40    Lock        - The lock to acquire
41
42Returns:
43
44    Lock owned
45
46--*/
47{
48    if (BS) {
49        if (BS->RaiseTPL != NULL) {
50            Lock->OwnerTpl = uefi_call_wrapper(BS->RaiseTPL, 1, Lock->Tpl);
51        }
52    }
53    else {
54        if (LibRuntimeRaiseTPL != NULL) {
55            Lock->OwnerTpl = LibRuntimeRaiseTPL(Lock->Tpl);
56        }
57    }
58    Lock->Lock += 1;
59    ASSERT (Lock->Lock == 1);
60}
61
62
63#ifndef __GNUC__
64#pragma RUNTIME_CODE(RtAcquireLock)
65#endif
66VOID
67RtReleaseLock (
68    IN FLOCK    *Lock
69    )
70/*++
71
72Routine Description:
73
74    Releases ownership of the mutual exclusion lock, and
75    restores the previous task priority level.
76
77Arguments:
78
79    Lock        - The lock to release
80
81Returns:
82
83    Lock unowned
84
85--*/
86{
87    EFI_TPL     Tpl;
88
89    Tpl = Lock->OwnerTpl;
90    ASSERT(Lock->Lock == 1);
91    Lock->Lock -= 1;
92    if (BS) {
93        if (BS->RestoreTPL != NULL) {
94            uefi_call_wrapper(BS->RestoreTPL, 1, Tpl);
95        }
96    }
97    else {
98        if (LibRuntimeRestoreTPL != NULL) {
99            LibRuntimeRestoreTPL(Tpl);
100        }
101    }
102}
103