Skip to content
Snippets Groups Projects
Commit 412eda6b authored by Michal Malý's avatar Michal Malý
Browse files

Unlock mutex when SpaceGroup cache object construction fails

parent d301768c
Branches
No related tags found
No related merge requests found
......@@ -42,6 +42,18 @@
#include "clipper_instance.h"
template<class Lockable>
class _MutexLocker {
public:
explicit _MutexLocker()
{
Lockable::mutex.lock();
}
~_MutexLocker()
{
Lockable::mutex.unlock();
}
};
namespace clipper {
......@@ -90,7 +102,8 @@ namespace clipper {
template<class T> typename ObjectCache<T>::Reference ObjectCache<T>::cache( const typename T::Key& key )
{
T::mutex.lock();
_MutexLocker<T> lk;
std::pair<int,T>* ptr = NULL;
// find existing data
for ( int i = 0; i < cache_.size(); i++ )
......@@ -115,7 +128,6 @@ namespace clipper {
}
}
Reference result( ptr );
T::mutex.unlock();
return result; // we have a ref to the new obj, so it is thread safe
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment