Skip to content

Commit

Permalink
removed mutexes from factory since we do not need them
Browse files Browse the repository at this point in the history
  • Loading branch information
drexlerd committed Nov 21, 2023
1 parent 5aa0ba6 commit 4b4aca9
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions include/dlplan/utils/factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ namespace dlplan {
template<typename T>
struct PerTypeCache {
std::unordered_map<T, std::weak_ptr<T>> data;
std::mutex mutex;
};

template<typename T>
Expand All @@ -23,7 +22,7 @@ struct GetOrCreateResult {
};


/// @brief A thread-safe reference-counted object cache.
/// @brief A reference-counted object cache.
/// Original idea by Herb Sutter.
/// Custom deleter idea: https://stackoverflow.com/questions/49782011/herb-sutters-10-liner-with-cleanup
template<typename... Ts>
Expand Down Expand Up @@ -54,7 +53,7 @@ class ReferenceCountedObjectFactory {
std::shared_ptr<T> sp;
auto& cached = t_cache->data[*element];
sp = cached.lock();
std::lock_guard<std::mutex> hold(t_cache->mutex);
// std::lock_guard<std::mutex> hold(t_cache->mutex);
bool new_insertion = false;

if (!sp) {
Expand All @@ -64,7 +63,7 @@ class ReferenceCountedObjectFactory {
[parent=t_cache, original_deleter=element.get_deleter()](T* x)
{
{
std::lock_guard<std::mutex> hold(parent->mutex);
// std::lock_guard<std::mutex> hold(parent->mutex);
parent->data.erase(*x);
}
/* After cache removal, we can call the objects destructor
Expand Down

0 comments on commit 4b4aca9

Please sign in to comment.