IxEthDBLocks_p.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /**
  2. * @file IxEthAccDBLocks_p.h
  3. *
  4. * @brief Definition of transaction lock stacks and lock utility macros
  5. *
  6. * @par
  7. * IXP400 SW Release version 2.0
  8. *
  9. * -- Copyright Notice --
  10. *
  11. * @par
  12. * Copyright 2001-2005, Intel Corporation.
  13. * All rights reserved.
  14. *
  15. * @par
  16. * SPDX-License-Identifier: BSD-3-Clause
  17. * @par
  18. * -- End of Copyright Notice --
  19. */
  20. #ifndef IxEthAccDBLocks_p_H
  21. #define IxEthAccDBLocks_p_H
  22. #include "IxOsPrintf.h"
  23. /* Lock and lock stacks */
  24. typedef struct
  25. {
  26. IxOsalFastMutex* locks[MAX_LOCKS];
  27. UINT32 stackPointer, basePointer;
  28. } LockStack;
  29. #define TRY_LOCK(mutex) \
  30. { \
  31. if (ixOsalFastMutexTryLock(mutex) != IX_SUCCESS) \
  32. { \
  33. return IX_ETH_DB_BUSY; \
  34. } \
  35. }
  36. #define UNLOCK(mutex) { ixOsalFastMutexUnlock(mutex); }
  37. #define INIT_STACK(stack) \
  38. { \
  39. (stack)->basePointer = 0; \
  40. (stack)->stackPointer = 0; \
  41. }
  42. #define PUSH_LOCK(stack, lock) \
  43. { \
  44. if ((stack)->stackPointer == MAX_LOCKS) \
  45. { \
  46. ERROR_LOG("Ethernet DB: maximum number of elements in a lock stack has been exceeded on push, heavy chaining?\n"); \
  47. UNROLL_STACK(stack); \
  48. \
  49. return IX_ETH_DB_NOMEM; \
  50. } \
  51. \
  52. if (ixOsalFastMutexTryLock(lock) == IX_SUCCESS) \
  53. { \
  54. (stack)->locks[(stack)->stackPointer++] = (lock); \
  55. } \
  56. else \
  57. { \
  58. UNROLL_STACK(stack); \
  59. \
  60. return IX_ETH_DB_BUSY; \
  61. } \
  62. }
  63. #define POP_LOCK(stack) \
  64. { \
  65. ixOsalFastMutexUnlock((stack)->locks[--(stack)->stackPointer]); \
  66. }
  67. #define UNROLL_STACK(stack) \
  68. { \
  69. while ((stack)->stackPointer > (stack)->basePointer) \
  70. { \
  71. POP_LOCK(stack); \
  72. } \
  73. }
  74. #define SHIFT_STACK(stack) \
  75. { \
  76. if ((stack)->basePointer == MAX_LOCKS - 1) \
  77. { \
  78. ERROR_LOG("Ethernet DB: maximum number of elements in a lock stack has been exceeded on shift, heavy chaining?\n"); \
  79. UNROLL_STACK(stack); \
  80. \
  81. return IX_ETH_DB_BUSY; \
  82. } \
  83. \
  84. ixOsalFastMutexUnlock((stack)->locks[(stack)->basePointer++]); \
  85. }
  86. #endif /* IxEthAccDBLocks_p_H */