1 /** @file 2 DXE Core library services. 3 4 Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR> 5 This program and the accompanying materials 6 are licensed and made available under the terms and conditions of the BSD License 7 which accompanies this distribution. The full text of the license may be found at 8 http://opensource.org/licenses/bsd-license.php 9 10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 12 13 **/ 14 15 #include "DxeMain.h" 16 17 // 18 // Lock Stuff 19 // 20 /** 21 Initialize a basic mutual exclusion lock. Each lock 22 provides mutual exclusion access at it's task priority 23 level. Since there is no-premption (at any TPL) or 24 multiprocessor support, acquiring the lock only consists 25 of raising to the locks TPL. 26 27 @param Lock The EFI_LOCK structure to initialize 28 29 @retval EFI_SUCCESS Lock Owned. 30 @retval EFI_ACCESS_DENIED Reentrant Lock Acquisition, Lock not Owned. 31 32 **/ 33 EFI_STATUS 34 CoreAcquireLockOrFail ( 35 IN EFI_LOCK *Lock 36 ) 37 { 38 ASSERT (Lock != NULL); 39 ASSERT (Lock->Lock != EfiLockUninitialized); 40 41 if (Lock->Lock == EfiLockAcquired) { 42 // 43 // Lock is already owned, so bail out 44 // 45 return EFI_ACCESS_DENIED; 46 } 47 48 Lock->OwnerTpl = CoreRaiseTpl (Lock->Tpl); 49 50 Lock->Lock = EfiLockAcquired; 51 return EFI_SUCCESS; 52 } 53 54 55 56 /** 57 Raising to the task priority level of the mutual exclusion 58 lock, and then acquires ownership of the lock. 59 60 @param Lock The lock to acquire 61 62 @return Lock owned 63 64 **/ 65 VOID 66 CoreAcquireLock ( 67 IN EFI_LOCK *Lock 68 ) 69 { 70 ASSERT (Lock != NULL); 71 ASSERT (Lock->Lock == EfiLockReleased); 72 73 Lock->OwnerTpl = CoreRaiseTpl (Lock->Tpl); 74 Lock->Lock = EfiLockAcquired; 75 } 76 77 78 79 /** 80 Releases ownership of the mutual exclusion lock, and 81 restores the previous task priority level. 82 83 @param Lock The lock to release 84 85 @return Lock unowned 86 87 **/ 88 VOID 89 CoreReleaseLock ( 90 IN EFI_LOCK *Lock 91 ) 92 { 93 EFI_TPL Tpl; 94 95 ASSERT (Lock != NULL); 96 ASSERT (Lock->Lock == EfiLockAcquired); 97 98 Tpl = Lock->OwnerTpl; 99 100 Lock->Lock = EfiLockReleased; 101 102 CoreRestoreTpl (Tpl); 103 } 104 105 106 107