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