IxEthDBLocks_p.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. * Redistribution and use in source and binary forms, with or without
  17. * modification, are permitted provided that the following conditions
  18. * are met:
  19. * 1. Redistributions of source code must retain the above copyright
  20. * notice, this list of conditions and the following disclaimer.
  21. * 2. Redistributions in binary form must reproduce the above copyright
  22. * notice, this list of conditions and the following disclaimer in the
  23. * documentation and/or other materials provided with the distribution.
  24. * 3. Neither the name of the Intel Corporation nor the names of its contributors
  25. * may be used to endorse or promote products derived from this software
  26. * without specific prior written permission.
  27. *
  28. * @par
  29. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
  30. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  31. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  32. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
  33. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  34. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  35. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  36. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  37. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  38. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  39. * SUCH DAMAGE.
  40. *
  41. * @par
  42. * -- End of Copyright Notice --
  43. */
  44. #ifndef IxEthAccDBLocks_p_H
  45. #define IxEthAccDBLocks_p_H
  46. #include "IxOsPrintf.h"
  47. /* Lock and lock stacks */
  48. typedef struct
  49. {
  50. IxOsalFastMutex* locks[MAX_LOCKS];
  51. UINT32 stackPointer, basePointer;
  52. } LockStack;
  53. #define TRY_LOCK(mutex) \
  54. { \
  55. if (ixOsalFastMutexTryLock(mutex) != IX_SUCCESS) \
  56. { \
  57. return IX_ETH_DB_BUSY; \
  58. } \
  59. }
  60. #define UNLOCK(mutex) { ixOsalFastMutexUnlock(mutex); }
  61. #define INIT_STACK(stack) \
  62. { \
  63. (stack)->basePointer = 0; \
  64. (stack)->stackPointer = 0; \
  65. }
  66. #define PUSH_LOCK(stack, lock) \
  67. { \
  68. if ((stack)->stackPointer == MAX_LOCKS) \
  69. { \
  70. ERROR_LOG("Ethernet DB: maximum number of elements in a lock stack has been exceeded on push, heavy chaining?\n"); \
  71. UNROLL_STACK(stack); \
  72. \
  73. return IX_ETH_DB_NOMEM; \
  74. } \
  75. \
  76. if (ixOsalFastMutexTryLock(lock) == IX_SUCCESS) \
  77. { \
  78. (stack)->locks[(stack)->stackPointer++] = (lock); \
  79. } \
  80. else \
  81. { \
  82. UNROLL_STACK(stack); \
  83. \
  84. return IX_ETH_DB_BUSY; \
  85. } \
  86. }
  87. #define POP_LOCK(stack) \
  88. { \
  89. ixOsalFastMutexUnlock((stack)->locks[--(stack)->stackPointer]); \
  90. }
  91. #define UNROLL_STACK(stack) \
  92. { \
  93. while ((stack)->stackPointer > (stack)->basePointer) \
  94. { \
  95. POP_LOCK(stack); \
  96. } \
  97. }
  98. #define SHIFT_STACK(stack) \
  99. { \
  100. if ((stack)->basePointer == MAX_LOCKS - 1) \
  101. { \
  102. ERROR_LOG("Ethernet DB: maximum number of elements in a lock stack has been exceeded on shift, heavy chaining?\n"); \
  103. UNROLL_STACK(stack); \
  104. \
  105. return IX_ETH_DB_BUSY; \
  106. } \
  107. \
  108. ixOsalFastMutexUnlock((stack)->locks[(stack)->basePointer++]); \
  109. }
  110. #endif /* IxEthAccDBLocks_p_H */