Use the new assert that doesn't crash the program in a release build

This commit is contained in:
Sebastian Messmer 2015-07-22 13:48:01 +02:00
parent ba4d619964
commit 14b6354d84

View File

@ -10,6 +10,7 @@
#include <type_traits> #include <type_traits>
#include <messmer/cpp-utils/macros.h> #include <messmer/cpp-utils/macros.h>
#include "ParallelAccessBaseStore.h" #include "ParallelAccessBaseStore.h"
#include <messmer/cpp-utils/assert/assert.h>
//TODO Refactor //TODO Refactor
@ -102,7 +103,7 @@ cpputils::unique_ref<ResourceRef> ParallelAccessStore<Resource, ResourceRef, Key
template<class Resource, class ResourceRef, class Key> template<class Resource, class ResourceRef, class Key>
cpputils::unique_ref<ResourceRef> ParallelAccessStore<Resource, ResourceRef, Key>::_add(const Key &key, cpputils::unique_ref<Resource> resource) { cpputils::unique_ref<ResourceRef> ParallelAccessStore<Resource, ResourceRef, Key>::_add(const Key &key, cpputils::unique_ref<Resource> resource) {
auto insertResult = _openResources.emplace(key, std::move(resource)); auto insertResult = _openResources.emplace(key, std::move(resource));
assert(true == insertResult.second); ASSERT(true == insertResult.second, "Inserting failed");
return _createResourceRef(insertResult.first->second.getReference(), key); return _createResourceRef(insertResult.first->second.getReference(), key);
} }
@ -132,7 +133,7 @@ boost::optional<cpputils::unique_ref<ResourceRef>> ParallelAccessStore<Resource,
template<class Resource, class ResourceRef, class Key> template<class Resource, class ResourceRef, class Key>
void ParallelAccessStore<Resource, ResourceRef, Key>::remove(const Key &key, cpputils::unique_ref<ResourceRef> resource) { void ParallelAccessStore<Resource, ResourceRef, Key>::remove(const Key &key, cpputils::unique_ref<ResourceRef> resource) {
auto insertResult = _resourcesToRemove.emplace(key, std::promise<cpputils::unique_ref<Resource>>()); auto insertResult = _resourcesToRemove.emplace(key, std::promise<cpputils::unique_ref<Resource>>());
assert(true == insertResult.second); ASSERT(true == insertResult.second, "Inserting failed");
cpputils::destruct(std::move(resource)); cpputils::destruct(std::move(resource));
//Wait for last resource user to release it //Wait for last resource user to release it
@ -146,7 +147,7 @@ template<class Resource, class ResourceRef, class Key>
void ParallelAccessStore<Resource, ResourceRef, Key>::release(const Key &key) { void ParallelAccessStore<Resource, ResourceRef, Key>::release(const Key &key) {
std::lock_guard<std::mutex> lock(_mutex); std::lock_guard<std::mutex> lock(_mutex);
auto found = _openResources.find(key); auto found = _openResources.find(key);
assert (found != _openResources.end()); ASSERT(found != _openResources.end(), "Didn't find key");
found->second.releaseReference(); found->second.releaseReference();
if (found->second.refCountIsZero()) { if (found->second.refCountIsZero()) {
auto foundToRemove = _resourcesToRemove.find(key); auto foundToRemove = _resourcesToRemove.find(key);