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