All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines
#include <Cache.h>
Public Member Functions | |
void | add (const CacheItem *sig) |
AllocatedCacheItem () | |
const CacheItem * | bestToFree () |
void | clear () |
int | count () const |
QString | humanInfo () const |
void | remove (const CacheItem *sig) |
~AllocatedCacheItem () |
QGpCoreTools::AllocatedCacheItem::AllocatedCacheItem | ( | ) | [inline] |
{}
{}
void QGpCoreTools::AllocatedCacheItem::add | ( | const CacheItem * | sig | ) | [inline] |
Referenced by QGpCoreTools::Cache::makeAvailable().
{append(sig);}
Returns the best item to free. It is either according to current CacheProcess or to last time items were touched in case of equality for the first criterium.
References QGpCoreTools::CacheItem::nextPredictedTime(), and TRACE.
{ TRACE; const CacheItem * bestItem=0; quint64 bestPredicted=0; quint64 bestAccess=0; quint64 t; for(iterator it=begin();it!=end();++it) { const CacheItem * item=*it; if(item->_dataLock.tryLock()) { if(item->_lockCount<2) { // Only the one of this try, hence not locked elsewhere t=item->nextPredictedTime(); if(t>bestPredicted) { if(bestItem) bestItem->_dataLock.unlock(); bestItem=item; bestPredicted=t; bestAccess=item->_lastAccess; } else if(t==bestPredicted) { t=item->_lastAccess; if(t<bestAccess) { if(bestItem) bestItem->_dataLock.unlock(); bestItem=item; bestAccess=t; } else { item->_dataLock.unlock(); } } else { item->_dataLock.unlock(); } } else { item->_dataLock.unlock(); } } } return bestItem; }
void QGpCoreTools::AllocatedCacheItem::clear | ( | ) | [inline] |
int QGpCoreTools::AllocatedCacheItem::count | ( | ) | const [inline] |
Referenced by humanInfo().
{return QList<const CacheItem *>::count();}
QString QGpCoreTools::AllocatedCacheItem::humanInfo | ( | ) | const |
Print information about allocated blocks (may be useful for checking memory usage of processes)
References count(), QGpCoreTools::CacheItem::dataSize(), QGpCoreTools::tr(), and TRACE.
Referenced by QGpCoreTools::Cache::enlarge(), and QGpCoreTools::Cache::makeAvailable().
{ TRACE; int sizeBlocks=0, sizeLockedBlocks=0, countLockedBlocks=0; for(const_iterator it=begin();it!=end();++it) { const CacheItem& item=**it; sizeBlocks+=item.dataSize(); if(item._dataLock.tryLock()) { if(item._lockCount>1) { // Not only the one of this try, hence locked elsewhere sizeLockedBlocks+=item.dataSize(); countLockedBlocks++; } item._dataLock.unlock(); } } return tr("%1 allocated blocks (%2 Mb), %3 locked blocks (%4 Mb)\n") .arg(count()).arg(sizeBlocks >> 20).arg(countLockedBlocks).arg(sizeLockedBlocks >> 20); }
void QGpCoreTools::AllocatedCacheItem::remove | ( | const CacheItem * | sig | ) | [inline] |
Referenced by QGpCoreTools::Cache::free().
{removeAt(indexOf(sig));}