+++ /dev/null
-/*++\r
-\r
-Copyright (c) 2004, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials \r
-are licensed and made available under the terms and conditions of the BSD License \r
-which accompanies this distribution. The full text of the license may be found at \r
-http://opensource.org/licenses/bsd-license.php \r
- \r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
-\r
-Module Name:\r
-\r
- Lock.c\r
-\r
-Abstract:\r
-\r
- Support for locking lib services.\r
-\r
---*/\r
-\r
-#include "Tiano.h"\r
-#include "EfiDriverLib.h"\r
-\r
-VOID\r
-EfiInitializeLock (\r
- IN OUT EFI_LOCK *Lock,\r
- IN EFI_TPL Priority\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Initialize a basic mutual exclusion lock. Each lock\r
- provides mutual exclusion access at it's task priority\r
- level. Since there is no-premption (at any TPL) or\r
- multiprocessor support, acquiring the lock only consists\r
- of raising to the locks TPL.\r
-\r
- Note on a check build ASSERT()s are used to ensure proper\r
- lock usage.\r
- \r
-Arguments:\r
-\r
- Lock - The EFI_LOCK structure to initialize\r
-\r
- Priority - The task priority level of the lock\r
-\r
- \r
-Returns:\r
-\r
- An initialized Efi Lock structure.\r
-\r
---*/\r
-{\r
- Lock->Tpl = Priority;\r
- Lock->OwnerTpl = 0;\r
- Lock->Lock = 0;\r
-}\r
-\r
-EFI_STATUS\r
-EfiAcquireLockOrFail (\r
- IN EFI_LOCK *Lock\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Initialize a basic mutual exclusion lock. Each lock\r
- provides mutual exclusion access at it's task priority\r
- level. Since there is no-premption (at any TPL) or\r
- multiprocessor support, acquiring the lock only consists\r
- of raising to the locks TPL.\r
- \r
-Arguments:\r
-\r
- Lock - The EFI_LOCK structure to initialize\r
- \r
-Returns:\r
-\r
- EFI_SUCCESS - Lock Owned.\r
- EFI_ACCESS_DENIED - Reentrant Lock Acquisition, Lock not Owned.\r
-\r
---*/\r
-{\r
- if (Lock->Lock != 0) {\r
- //\r
- // Lock is already owned, so bail out\r
- //\r
- return EFI_ACCESS_DENIED;\r
- }\r
-\r
- Lock->OwnerTpl = gBS->RaiseTPL (Lock->Tpl);\r
-\r
- Lock->Lock += 1;\r
- return EFI_SUCCESS;\r
-}\r
-\r
-VOID\r
-EfiAcquireLock (\r
- IN EFI_LOCK *Lock\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Raising to the task priority level of the mutual exclusion\r
- lock, and then acquires ownership of the lock.\r
- \r
-Arguments:\r
-\r
- Lock - The lock to acquire\r
- \r
-Returns:\r
-\r
- Lock owned\r
-\r
---*/\r
-{\r
- EFI_STATUS Status;\r
-\r
- Status = EfiAcquireLockOrFail (Lock);\r
-\r
- //\r
- // Lock was already locked.\r
- //\r
- ASSERT_EFI_ERROR (Status);\r
-}\r
-\r
-VOID\r
-EfiReleaseLock (\r
- IN EFI_LOCK *Lock\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Releases ownership of the mutual exclusion lock, and\r
- restores the previous task priority level.\r
- \r
-Arguments:\r
-\r
- Lock - The lock to release\r
- \r
-Returns:\r
-\r
- Lock unowned\r
-\r
---*/\r
-{\r
- EFI_TPL Tpl;\r
-\r
- Tpl = Lock->OwnerTpl;\r
-\r
- ASSERT (Lock->Lock == 1);\r
- Lock->Lock -= 1;\r
-\r
- gBS->RestoreTPL (Tpl);\r
-}\r