only return locked FontStack objects
This commit is contained in:
30
include/mbgl/util/exclusive.hpp
Normal file
30
include/mbgl/util/exclusive.hpp
Normal 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
|
||||
Reference in New Issue
Block a user