#include "SynchronizedBlockStore.h" using std::unique_ptr; using std::make_unique; using std::string; namespace blockstore { namespace synchronized { SynchronizedBlockStore::SynchronizedBlockStore(unique_ptr baseBlockStore) : _baseBlockStore(std::move(baseBlockStore)), _openBlockList() { } unique_ptr SynchronizedBlockStore::create(size_t size) { return _openBlockList.insert(_baseBlockStore->create(size)); } unique_ptr SynchronizedBlockStore::load(const Key &key) { return _openBlockList.acquire(key, [this, key] { return _baseBlockStore->load(key); }); } void SynchronizedBlockStore::remove(unique_ptr block) { //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) { // _baseBlockStore->remove(block); //}); } uint64_t SynchronizedBlockStore::numBlocks() const { return _baseBlockStore->numBlocks(); } } }