2015-03-19 11:16:20 +01:00
|
|
|
#include "SynchronizedBlockStore.h"
|
|
|
|
|
|
|
|
using std::unique_ptr;
|
|
|
|
using std::make_unique;
|
|
|
|
using std::string;
|
|
|
|
|
|
|
|
namespace blockstore {
|
|
|
|
namespace synchronized {
|
|
|
|
|
|
|
|
SynchronizedBlockStore::SynchronizedBlockStore(unique_ptr<BlockStore> baseBlockStore)
|
2015-03-28 18:44:22 +01:00
|
|
|
: _baseBlockStore(std::move(baseBlockStore)),
|
|
|
|
_openBlockList() {
|
|
|
|
}
|
2015-03-19 11:16:20 +01:00
|
|
|
|
|
|
|
unique_ptr<Block> SynchronizedBlockStore::create(size_t size) {
|
2015-03-28 18:44:22 +01:00
|
|
|
return _openBlockList.insert(_baseBlockStore->create(size));
|
2015-03-19 11:16:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
unique_ptr<Block> SynchronizedBlockStore::load(const Key &key) {
|
2015-03-28 18:44:22 +01:00
|
|
|
return _openBlockList.acquire(key, [this, key] {
|
|
|
|
return _baseBlockStore->load(key);
|
|
|
|
});
|
2015-03-19 11:16:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void SynchronizedBlockStore::remove(unique_ptr<Block> block) {
|
2015-03-28 18:44:22 +01:00
|
|
|
//TODO
|
|
|
|
//Remove from openBlockList, therefore close it, and second parameter is meant to be an onClose event handler
|
|
|
|
//(called after all threads wanting to work with the block have been satisfied).
|
|
|
|
//But is quite unreadable here this way...
|
|
|
|
//_openBlockList.remove(std::move(block), [] (unique_ptr<Block> block) {
|
|
|
|
// _baseBlockStore->remove(block);
|
|
|
|
//});
|
2015-03-19 11:16:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t SynchronizedBlockStore::numBlocks() const {
|
|
|
|
return _baseBlockStore->numBlocks();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|