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 45#ifndef IxEthAccDBLocks_p_H 46#define IxEthAccDBLocks_p_H 47 48#include "IxOsPrintf.h" 49 50/* Lock and lock stacks */ 51typedef struct 52{ 53 IxOsalFastMutex* locks[MAX_LOCKS]; 54 UINT32 stackPointer, basePointer; 55} LockStack; 56 57#define TRY_LOCK(mutex) \ 58 { \ 59 if (ixOsalFastMutexTryLock(mutex) != IX_SUCCESS) \ 60 { \ 61 return IX_ETH_DB_BUSY; \ 62 } \ 63 } 64 65 66#define UNLOCK(mutex) { ixOsalFastMutexUnlock(mutex); } 67 68#define INIT_STACK(stack) \ 69 { \ 70 (stack)->basePointer = 0; \ 71 (stack)->stackPointer = 0; \ 72 } 73 74#define PUSH_LOCK(stack, lock) \ 75 { \ 76 if ((stack)->stackPointer == MAX_LOCKS) \ 77 { \ 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); \ 80 \ 81 return IX_ETH_DB_NOMEM; \ 82 } \ 83 \ 84 if (ixOsalFastMutexTryLock(lock) == IX_SUCCESS) \ 85 { \ 86 (stack)->locks[(stack)->stackPointer++] = (lock); \ 87 } \ 88 else \ 89 { \ 90 UNROLL_STACK(stack); \ 91 \ 92 return IX_ETH_DB_BUSY; \ 93 } \ 94 } 95 96#define POP_LOCK(stack) \ 97 { \ 98 ixOsalFastMutexUnlock((stack)->locks[--(stack)->stackPointer]); \ 99 } 100 101#define UNROLL_STACK(stack) \ 102 { \ 103 while ((stack)->stackPointer > (stack)->basePointer) \ 104 { \ 105 POP_LOCK(stack); \ 106 } \ 107 } 108 109#define SHIFT_STACK(stack) \ 110 { \ 111 if ((stack)->basePointer == MAX_LOCKS - 1) \ 112 { \ 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); \ 115 \ 116 return IX_ETH_DB_BUSY; \ 117 } \ 118 \ 119 ixOsalFastMutexUnlock((stack)->locks[(stack)->basePointer++]); \ 120 } 121 122#endif /* IxEthAccDBLocks_p_H */ 123