2 * @file IxEthAccDBLocks_p.h
4 * @brief Definition of transaction lock stacks and lock utility macros
7 * IXP400 SW Release version 2.0
9 * -- Copyright Notice --
12 * Copyright 2001-2005, Intel Corporation.
13 * All rights reserved.
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
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.
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
42 * -- End of Copyright Notice --
45 #ifndef IxEthAccDBLocks_p_H
46 #define IxEthAccDBLocks_p_H
48 #include "IxOsPrintf.h"
50 /* Lock and lock stacks */
53 IxOsalFastMutex* locks[MAX_LOCKS];
54 UINT32 stackPointer, basePointer;
57 #define TRY_LOCK(mutex) \
59 if (ixOsalFastMutexTryLock(mutex) != IX_SUCCESS) \
61 return IX_ETH_DB_BUSY; \
66 #define UNLOCK(mutex) { ixOsalFastMutexUnlock(mutex); }
68 #define INIT_STACK(stack) \
70 (stack)->basePointer = 0; \
71 (stack)->stackPointer = 0; \
74 #define PUSH_LOCK(stack, lock) \
76 if ((stack)->stackPointer == MAX_LOCKS) \
78 ERROR_LOG("Ethernet DB: maximum number of elements in a lock stack has been exceeded on push, heavy chaining?\n"); \
79 UNROLL_STACK(stack); \
81 return IX_ETH_DB_NOMEM; \
84 if (ixOsalFastMutexTryLock(lock) == IX_SUCCESS) \
86 (stack)->locks[(stack)->stackPointer++] = (lock); \
90 UNROLL_STACK(stack); \
92 return IX_ETH_DB_BUSY; \
96 #define POP_LOCK(stack) \
98 ixOsalFastMutexUnlock((stack)->locks[--(stack)->stackPointer]); \
101 #define UNROLL_STACK(stack) \
103 while ((stack)->stackPointer > (stack)->basePointer) \
109 #define SHIFT_STACK(stack) \
111 if ((stack)->basePointer == MAX_LOCKS - 1) \
113 ERROR_LOG("Ethernet DB: maximum number of elements in a lock stack has been exceeded on shift, heavy chaining?\n"); \
114 UNROLL_STACK(stack); \
116 return IX_ETH_DB_BUSY; \
119 ixOsalFastMutexUnlock((stack)->locks[(stack)->basePointer++]); \
122 #endif /* IxEthAccDBLocks_p_H */