19 #ifndef SUPER_POOL_HPP
20 #define SUPER_POOL_HPP
22 #include <ndb_global.h>
25 #include <ErrorReporter.hpp>
243 SuperPool(Uint32 pageSize, Uint32 pageBits);
252 void addHeadPage(
PageList& pl, PtrI pageI);
255 void addTailPage(
PageList& pl, PtrI pageI);
258 void removePage(
PageList& pl, PtrI pageI);
261 PageEnt& getPageEnt(PtrI pageI);
264 void* getPageP(PtrI pageI);
268 PtrI getPageI(
void* pageP);
285 void* getRecP(PtrI recI,
RecInfo& ri);
288 Uint32 getFreeCount(
RecInfo& ri, PtrI freeRecPtrI);
291 Uint32 getRecPageCount(
RecInfo& ri);
294 Uint32 getRecTotCount(
RecInfo& ri);
297 Uint32 getRecUseCount(
RecInfo& ri);
303 void addCurrPage(
RecInfo& ri, PtrI pageI);
306 void removeCurrPage(
RecInfo& ri);
310 bool getAvailPage(
RecInfo& ri);
323 virtual PtrI getNewPage() = 0;
326 void initFreePage(
RecInfo& ri, PtrI pageI);
329 void releaseNotCurrent(
RecInfo& ri, PtrI recI);
332 void freeRecPages(
RecInfo& ri);
335 void freeAllRecPages(
RecInfo& ri,
bool force);
339 void setInitPages(Uint32 initPages);
340 void setIncrPages(Uint32 incrPages);
341 void setMaxPages(Uint32 maxPages);
344 Uint32 getGpMinPages();
355 virtual bool allocMemory() = 0;
362 const Uint32 m_pageSize;
363 const Uint16 m_pageBits;
364 const Uint16 m_recBits;
365 const Uint32 m_recMask;
379 Uint32 m_groupMinPct;
380 Uint32 m_groupMinPages;
381 Uint32 m_groupTotPages;
385 SuperPool::getPageEnt(PtrI pageI)
387 Uint32 ip = pageI >> m_recBits;
388 return m_pageEnt[ip];
392 SuperPool::getPageP(PtrI ptrI)
394 Int32 ip = (Int32)ptrI >> m_recBits;
395 return (Uint8*)m_memRoot + ip * (my_ptrdiff_t)m_pageSize;
399 SuperPool::getRecP(PtrI ptrI, RecInfo& ri)
401 Uint32 ip = ptrI >> m_recBits;
402 assert(m_pageType[ip] == (ri.m_recType & 0xFF));
403 Uint32 ir = ptrI & m_recMask;
404 return (Uint8*)getPageP(ptrI) + ir * ri.m_recSize;
423 void setMinPct(Uint32 resPct);
426 void setMinPages(Uint32 resPages);
461 void freeAllRecPages(
bool force);
470 m_superPool(gp.m_superPool),
471 m_recInfo(gp, sizeof(T))
479 freeAllRecPages(
true);
486 void* recP = m_superPool.getRecP(ptr.i, m_recInfo);
487 ptr.p =
static_cast<T*
>(recP);
496 Uint32 recMask = sp.m_recMask;
498 if ((ri.m_freeRecI & recMask) != recMask ||
499 sp.getAvailPage(ri)) {
500 SuperPool::PtrI recI = ri.m_freeRecI;
501 void* recP = sp.getRecP(recI, ri);
502 ri.m_freeRecI = *(Uint32*)recP;
504 ptr.p =
static_cast<T*
>(recP);
518 SuperPool::PtrI recI = ptr.i;
519 Uint32 recMask = sp.m_recMask;
521 if ((recI & ~recMask) == (ri.m_freeRecI & ~recMask)) {
522 void* recP = sp.getRecP(recI, ri);
523 *(Uint32*)recP = ri.m_freeRecI;
524 ri.m_freeRecI = recI;
526 sp.releaseNotCurrent(ri, recI);
537 sp.freeAllRecPages(m_recInfo, force);
570 HeapPool(Uint32 pageSize, Uint32 pageBits);
576 virtual PtrI getNewPage();
582 bool allocArea(
Area* ap, Uint32 tryPages);
585 virtual bool allocMemory() {
return allocMemoryImpl();}
586 bool allocMemoryImpl();