only return locked FontStack objects

This commit is contained in:
Konstantin Käfer
2015-05-19 15:13:05 +02:00
parent b0c89e7f44
commit bcf66b7449
3 changed files with 40 additions and 19 deletions

View File

@@ -0,0 +1,30 @@
#ifndef MBGL_UTIL_EXCLUSIVE
#define MBGL_UTIL_EXCLUSIVE
#include <memory>
#include <mutex>
namespace mbgl {
namespace util {
template <class T>
class exclusive {
public:
inline exclusive(T* val, std::unique_ptr<std::lock_guard<std::mutex>> mtx) : ptr(val), lock(std::move(mtx)) {}
inline T* operator->() { return ptr; }
inline const T* operator->() const { return ptr; }
inline T* operator*() { return ptr; }
inline const T* operator*() const { return ptr; }
private:
T *ptr;
std::unique_ptr<std::lock_guard<std::mutex>> lock;
};
} // end namespace util
} // end namespace mbgl
#endif