int FileBufferMgr::bulkInsert(const vector<CacheInsert_t> &ops) { uint32_t i; int32_t pi; int ret = 0; mutex::scoped_lock lk(fWLock); for (i = 0; i < ops.size(); i++) { const CacheInsert_t &op = ops[i]; if (gPMProfOn && gPMStatsPtr) #ifdef _MSC_VER gPMStatsPtr->markEvent(op.lbid, GetCurrentThreadId(), gSession, 'I'); #else gPMStatsPtr->markEvent(op.lbid, pthread_self(), gSession, 'I'); #endif HashObject_t fbIndex(op.lbid, op.ver, 0); filebuffer_pair_t pr = fbSet.insert(fbIndex); if (!pr.second) { if (gPMProfOn && gPMStatsPtr) #ifdef _MSC_VER gPMStatsPtr->markEvent(op.lbid, GetCurrentThreadId(), gSession, 'D'); #else gPMStatsPtr->markEvent(op.lbid, pthread_self(), gSession, 'D'); #endif continue; } //cout << "FBM: inserting <" << op.lbid << ", " << op.ver << endl; fCacheSize++; fBlksLoaded++; FBData_t fbdata = {op.lbid, op.ver, 0}; updateLRU(fbdata); pi = doBlockCopy(op.lbid, op.ver, op.data); HashObject_t &ref = const_cast<HashObject_t &>(*pr.first); ref.poolIdx = pi; fFBPool[pi].listLoc(fbList.begin()); if (gPMProfOn && gPMStatsPtr) #ifdef _MSC_VER gPMStatsPtr->markEvent(op.lbid, GetCurrentThreadId(), gSession, 'J'); #else gPMStatsPtr->markEvent(op.lbid, pthread_self(), gSession, 'J'); #endif ret++; } idbassert(fCacheSize <= maxCacheSize()); return ret; }
GLuint QOpenGL2GradientCache::addCacheElement(quint64 hash_val, const QGradient &gradient, qreal opacity) { QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions(); if (cache.size() == maxCacheSize()) { int elem_to_remove = qrand() % maxCacheSize(); quint64 key = cache.keys()[elem_to_remove]; // need to call glDeleteTextures on each removed cache entry: QOpenGLGradientColorTableHash::const_iterator it = cache.constFind(key); do { funcs->glDeleteTextures(1, &it.value().texId); } while (++it != cache.constEnd() && it.key() == key); cache.remove(key); // may remove more than 1, but OK } CacheInfo cache_entry(gradient.stops(), opacity, gradient.interpolationMode()); uint buffer[1024]; generateGradientColorTable(gradient, buffer, paletteSize(), opacity); funcs->glGenTextures(1, &cache_entry.texId); funcs->glBindTexture(GL_TEXTURE_2D, cache_entry.texId); funcs->glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, paletteSize(), 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer); return cache.insert(hash_val, cache_entry).value().texId; }
void ThreadedDyscoColumn<DataType>::storeBlock() { // Put the data of the current block into the cache so that the parallell threads can write them mutex::scoped_lock lock(_mutex); CacheItem *item = new CacheItem(std::move(_timeBlockBuffer)); // Wait until there is space available AND the row to be written is not in the cache typename cache_t::iterator cacheItemPtr = _cache.find(_currentBlock); while(_cache.size() >= maxCacheSize() || cacheItemPtr != _cache.end()) { _cacheChangedCondition.wait(lock); cacheItemPtr = _cache.find(_currentBlock); } _cache.insert(typename cache_t::value_type(_currentBlock, item)); _cacheChangedCondition.notify_all(); lock.unlock(); _isCurrentBlockChanged = false; const size_t nPolarizations = _shape[0], nChannels = _shape[1]; _timeBlockBuffer.reset(new TimeBlockBuffer<data_t>(nPolarizations, nChannels)); //_timeBlockBuffer->SetNAntennae(_antennaCount); }
// puts the new entry at the front of the list void FileBufferMgr::updateLRU(const FBData_t &f) { if (fCacheSize > maxCacheSize()) { list<FBData_t>::iterator last = fbList.end(); last--; FBData_t &fbdata = *last; HashObject_t lastFB(fbdata.lbid, fbdata.ver, 0); filebuffer_uset_iter_t iter = fbSet.find(lastFB); fEmptyPoolSlots.push_back(iter->poolIdx); if (fbdata.hits == 0) fBlksNotUsed++; fbSet.erase(iter); fbList.splice(fbList.begin(), fbList, last); fbdata = f; fCacheSize--; //cout << "booted an entry\n"; } else { //cout << "new entry\n"; fbList.push_front(f); } }
int FileBufferMgr::insert(const BRM::LBID_t lbid, const BRM::VER_t ver, const uint8_t* data) { int ret=0; if (gPMProfOn && gPMStatsPtr) #ifdef _MSC_VER gPMStatsPtr->markEvent(lbid, GetCurrentThreadId(), gSession, 'I'); #else gPMStatsPtr->markEvent(lbid, pthread_self(), gSession, 'I'); #endif mutex::scoped_lock lk(fWLock); HashObject_t fbIndex(lbid, ver, 0); filebuffer_pair_t pr = fbSet.insert(fbIndex); if (pr.second) { // It was inserted (it wasn't there before) // Right now we have an invalid cache: we have inserted an entry with a -1 index. // We need to fix this quickly... fCacheSize++; FBData_t fbdata = {lbid, ver, 0}; fbList.push_front(fbdata); fBlksLoaded++; if (fReportFrequency && (fBlksLoaded%fReportFrequency)==0) { struct timespec tm; clock_gettime(CLOCK_MONOTONIC, &tm); fLog << left << fixed << ((double)(tm.tv_sec+(1.e-9*tm.tv_nsec))) << " " << right << setw(12) << fBlksLoaded << " " << right << setw(12) << fBlksNotUsed << endl; } } else { // if it's a duplicate there's nothing to do if (gPMProfOn && gPMStatsPtr) #ifdef _MSC_VER gPMStatsPtr->markEvent(lbid, GetCurrentThreadId(), gSession, 'D'); #else gPMStatsPtr->markEvent(lbid, pthread_self(), gSession, 'D'); #endif return ret; } uint32_t pi = numeric_limits<int>::max(); if (fCacheSize > maxCacheSize()) { // If the insert above caused the cache to exceed its max size, find the lru block in // the cache and use its pool index to store the block data. FBData_t &fbdata = fbList.back(); //the lru block HashObject_t lastFB(fbdata.lbid, fbdata.ver, 0); filebuffer_uset_iter_t iter = fbSet.find( lastFB ); //should be there idbassert(iter != fbSet.end()); pi = iter->poolIdx; idbassert(pi < maxCacheSize()); idbassert(pi < fFBPool.size()); // set iters are always const. We are not changing the hash here, and this gets us // the pointer we need cheaply... HashObject_t &ref = const_cast<HashObject_t &>(*pr.first); ref.poolIdx = pi; //replace the lru block with this block FileBuffer fb(lbid, ver, NULL, 0); fFBPool[pi] = fb; fFBPool[pi].setData(data, 8192); fbSet.erase(iter); if (fbList.back().hits==0) fBlksNotUsed++; fbList.pop_back(); fCacheSize--; depleteCache(); ret=1; } else { if ( ! fEmptyPoolSlots.empty() ) { pi = fEmptyPoolSlots.front(); fEmptyPoolSlots.pop_front(); FileBuffer fb(lbid, ver, NULL, 0); fFBPool[pi] = fb; fFBPool[pi].setData(data, 8192); } else { pi = fFBPool.size(); FileBuffer fb(lbid, ver, NULL, 0); fFBPool.push_back(fb); fFBPool[pi].setData(data, 8192); } // See comment above HashObject_t &ref = const_cast<HashObject_t &>(*pr.first); ref.poolIdx = pi; ret=1; } idbassert(pi < fFBPool.size()); fFBPool[pi].listLoc(fbList.begin()); if (gPMProfOn && gPMStatsPtr) #ifdef _MSC_VER gPMStatsPtr->markEvent(lbid, GetCurrentThreadId(), gSession, 'J'); #else gPMStatsPtr->markEvent(lbid, pthread_self(), gSession, 'J'); #endif idbassert(fCacheSize <= maxCacheSize()); // idbassert(fCacheSize == fbSet.size()); // idbassert(fCacheSize == fbList.size()); return ret; }