rtlock.c 1.5 KB

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