/* Copyright (c) 2003, 2005, 2006 MySQL AB This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ #ifndef DLC_FIFOLIST_HPP #define DLC_FIFOLIST_HPP #include "DLFifoList.hpp" #include // Adds "count" to DLFifoList template class DLCFifoList : public DLFifoList { public: // List head struct Head : public DLFifoList::Head { Head() : m_count(0) {} Uint32 m_count; }; // Ctor DLCFifoList(ArrayPool & thePool) : DLFifoList(thePool) {} // Get count Uint32 count() const { return head.m_count; } // Redefine methods which do add or remove bool seize(Ptr& ptr) { if (DLFifoList::seize(ptr)) { head.m_count++; return true; } return false; } bool seizeId(Ptr& ptr, Uint32 i) { if (DLFifoList::seizeId(ptr)) { head.m_count++; return true; } return false; } void add(Ptr& ptr) { DLFifoList::add(ptr); head.m_count++; } void remove(Ptr& ptr) { DLFifoList::remove(ptr); head.m_count--; } void release(Uint32 i) { DLFifoList::release(i); head.m_count--; } void release(Ptr& ptr) { DLFifoList::release(ptr); head.m_count--; } void release() { DLFifoList::release(); head.m_count = 0; } DLCFifoList& operator=(const DLCFifoList& src){ assert(&this->thePool == &src.thePool); this->head = src.head; return * this; } protected: Head head; }; // Local variant template class LocalDLCFifoList : public DLCFifoList { public: LocalDLCFifoList(ArrayPool & thePool, typename DLCFifoList::Head &_src) : DLCFifoList(thePool), src(_src) { this->head = src; #ifdef VM_TRACE assert(src.in_use == false); src.in_use = true; #endif } ~LocalDLCFifoList() { #ifdef VM_TRACE assert(src.in_use == true); #endif src = this->head; } private: typename DLCFifoList::Head & src; }; #endif