summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2015-02-11 14:03:44 -0800
committerKonstantin Käfer <mail@kkaefer.com>2015-03-06 15:42:34 +0100
commitc30bb1a9f80a7a772578d8742e122c013a56202d (patch)
tree177f3ff07634b655d65ef18872aae2c2241a6247 /include
parente00bae4f1c9fed201dd01f641f7849d4178e0e7c (diff)
downloadqtlocation-mapboxgl-c30bb1a9f80a7a772578d8742e122c013a56202d.tar.gz
add more locking around GlyphStore and FontStack
this is a stopgap until we have a solution that gives every worker thread their own copy
Diffstat (limited to 'include')
-rw-r--r--include/mbgl/util/uv.hpp33
1 files changed, 33 insertions, 0 deletions
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 T>
+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<mutex> &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);