From c30bb1a9f80a7a772578d8742e122c013a56202d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Wed, 11 Feb 2015 14:03:44 -0800 Subject: add more locking around GlyphStore and FontStack this is a stopgap until we have a solution that gives every worker thread their own copy --- include/mbgl/util/uv.hpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'include/mbgl/util/uv.hpp') diff --git a/include/mbgl/util/uv.hpp b/include/mbgl/util/uv.hpp index 169bee1912..1183394681 100644 --- a/include/mbgl/util/uv.hpp +++ b/include/mbgl/util/uv.hpp @@ -60,6 +60,39 @@ private: rwlock *mtx = nullptr; }; +template +class exclusive { +public: + exclusive(T& val, mutex &mtx) : ptr(&val), lock(mtx) {} + exclusive(T *val, mutex &mtx) : ptr(val), lock(mtx) {} + exclusive(mutex &mtx) : lock(mtx) {} + exclusive(const std::unique_ptr &mtx) : lock(mtx) {} + exclusive(const exclusive &) = delete; + exclusive(exclusive &&) = default; + exclusive &operator=(const exclusive &) = delete; + exclusive &operator=(exclusive &&) = default; + + T *operator->() { return ptr; } + const T *operator->() const { return ptr; } + T *operator*() { return ptr; } + const T *operator*() const { return ptr; } + operator T&() { return *ptr; } + operator const T&() const { return *ptr; } + + void operator<<(T& val) { operator<<(&val); } + void operator<<(T *val) { + if (ptr) { + throw std::runtime_error("exclusive<> was assigned before"); + } + ptr = val; + } + +private: + T *ptr = nullptr; + lock lock; +}; + + const char *getFileRequestError(uv_fs_t *req); -- cgit v1.2.1