Files
Sourcetrail/src/lib/data/storage/StorageProvider.cpp
T
Andreas Stallinger 37ead804bf src: clazy compiler warnings
get rid of most clazy warnings (https://github.com/KDE/clazy)
* range loop use refs
* qcolor ctor with ints
* missing Q_OBJECT macro
* use .constfirst instead of .first

enabled ccache for unix systems for fasterr recompiling
* if ccache is in path we use it now
2017-08-10 09:45:55 +02:00

73 lines
1.6 KiB
C++

#include "data/storage/StorageProvider.h"
#include "utility/logging/logging.h"
int StorageProvider::getStorageCount() const
{
std::lock_guard<std::mutex> lock(m_storagesMutex);
return m_storages.size();
}
void StorageProvider::insert(std::shared_ptr<IntermediateStorage> storage)
{
const std::size_t storageSize = storage->getSourceLocationCount();
std::list<std::shared_ptr<IntermediateStorage>>::iterator it;
std::lock_guard<std::mutex> lock(m_storagesMutex);
for (it = m_storages.begin(); it != m_storages.end(); it++)
{
if ((*it)->getSourceLocationCount() < storageSize)
{
break;
}
}
m_storages.insert(it, storage);
}
std::shared_ptr<IntermediateStorage> StorageProvider::consumeSecondLargestStorage()
{
std::shared_ptr<IntermediateStorage> ret;
{
std::lock_guard<std::mutex> lock(m_storagesMutex);
if (m_storages.size() > 1)
{
std::list<std::shared_ptr<IntermediateStorage>>::iterator it = m_storages.begin();
it++;
ret = *it;
m_storages.erase(it);
}
}
return ret;
}
std::shared_ptr<IntermediateStorage> StorageProvider::consumeLargestStorage()
{
std::shared_ptr<IntermediateStorage> ret;
{
std::lock_guard<std::mutex> lock(m_storagesMutex);
if (!m_storages.empty())
{
ret = m_storages.front();
m_storages.pop_front();
}
}
return ret;
}
void StorageProvider::logCurrentState() const
{
std::string logString = "Storages waiting for injection:";
{
std::lock_guard<std::mutex> lock(m_storagesMutex);
for (const std::shared_ptr<IntermediateStorage>& storage: m_storages)
{
logString += " " + std::to_string(storage->getSourceLocationCount()) + ";";
}
}
LOG_INFO(logString);
}