1 /* 2 Copyright (C) 2007, 2008 MySQL AB 3 All rights reserved. Use is subject to license terms. 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License, version 2.0, 7 as published by the Free Software Foundation. 8 9 This program is also distributed with certain software (including 10 but not limited to OpenSSL) that is licensed under separate terms, 11 as designated in a particular file or component or in included license 12 documentation. The authors of MySQL hereby grant you an additional 13 permission to link the program and your derivative works with the 14 separately licensed software that they have included with MySQL. 15 16 This program is distributed in the hope that it will be useful, 17 but WITHOUT ANY WARRANTY; without even the implied warranty of 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 GNU General Public License, version 2.0, for more details. 20 21 You should have received a copy of the GNU General Public License 22 along with this program; if not, write to the Free Software 23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 24 */ 25 26 #ifndef BLOCK_MUTEX_IMPL_HPP 27 #define BLOCK_MUTEX_IMPL_HPP 28 29 #include "ArrayPool.hpp" 30 #include "DLFifoList.hpp" 31 #include "KeyTable.hpp" 32 #include <signaldata/UtilLock.hpp> 33 34 class LockQueue 35 { 36 public: LockQueue()37 LockQueue() {} 38 39 /** 40 * A lock queue element 41 */ 42 struct LockQueueElement 43 { LockQueueElementLockQueue::LockQueueElement44 LockQueueElement() {} 45 46 UtilLockReq m_req; 47 union { 48 Uint32 nextPool; 49 Uint32 nextList; 50 }; 51 Uint32 prevList; 52 }; 53 54 typedef ArrayPool<LockQueueElement> Pool; 55 56 Uint32 lock(SimulatedBlock*, 57 Pool&, const UtilLockReq*, const UtilLockReq** = 0); 58 Uint32 unlock(SimulatedBlock*, 59 Pool&, const UtilUnlockReq* req); 60 61 /** 62 * After unlock 63 */ 64 struct Iterator 65 { 66 SimulatedBlock* m_block; 67 Pool * thePool; 68 Ptr<LockQueueElement> m_prev; 69 Ptr<LockQueueElement> m_curr; 70 }; 71 72 bool first(SimulatedBlock*, Pool& pool, Iterator&); 73 bool next(Iterator&); 74 75 /** 76 * 0 - done 77 * 1 - already granted 78 * 2 - needs conf 79 */ 80 int checkLockGrant(Iterator &, UtilLockReq * req); 81 82 /** 83 * Clear lock queue 84 */ 85 void clear (Pool&); 86 87 /** 88 * Dump 89 */ 90 void dump_queue(Pool&, SimulatedBlock* block); 91 92 private: 93 /** 94 * The actual lock queue 95 */ 96 DLFifoList<LockQueueElement>::Head m_queue; 97 }; 98 99 #endif 100