From fa2fd348491cddef0a356fb13a8dab0d2e91d5fb Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 21 Jan 2018 00:41:34 +0100 Subject: Replace glib quarks --- ingen/URIMap.hpp | 12 +++++++++++- src/URIMap.cpp | 28 +++++++++++++++++++++------- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/ingen/URIMap.hpp b/ingen/URIMap.hpp index 6ad8c684..fc402c2c 100644 --- a/ingen/URIMap.hpp +++ b/ingen/URIMap.hpp @@ -18,8 +18,11 @@ #define INGEN_URIMAP_HPP #include +#include #include +#include #include +#include #include "ingen/LV2Features.hpp" #include "ingen/ingen.h" @@ -65,7 +68,7 @@ public: struct URIDMapFeature : public Feature { URIDMapFeature(URIMap* map, LV2_URID_Map* impl, Log& log); LV2_URID map(const char* uri); - static LV2_URID default_map(LV2_URID_Map_Handle h, const char* uri); + static LV2_URID default_map(LV2_URID_Map_Handle h, const char* c_uri); LV2_URID_Map urid_map; Log& log; }; @@ -81,8 +84,15 @@ public: SPtr urid_unmap_feature() { return _urid_unmap_feature; } private: + friend class URIDMapFeature; + friend class URIDUnMapFeature; + SPtr _urid_map_feature; SPtr _urid_unmap_feature; + + std::mutex _mutex; + std::unordered_map _map; + std::vector _unmap; }; } // namespace Ingen diff --git a/src/URIMap.cpp b/src/URIMap.cpp index 01d48c00..9ce1f178 100644 --- a/src/URIMap.cpp +++ b/src/URIMap.cpp @@ -16,8 +16,6 @@ #include -#include - #include "ingen/Log.hpp" #include "ingen/URI.hpp" #include "ingen/URIMap.hpp" @@ -40,15 +38,26 @@ URIMap::URIDMapFeature::URIDMapFeature(URIMap* map, urid_map = *impl; } else { urid_map.map = default_map; - urid_map.handle = nullptr; + urid_map.handle = map; } } LV2_URID URIMap::URIDMapFeature::default_map(LV2_URID_Map_Handle h, - const char* uri) + const char* c_uri) { - return static_cast(g_quark_from_string(uri)); + URIMap* const map((URIMap*)h); + std::string uri(c_uri); + std::lock_guard lock(map->_mutex); + + auto record = map->_map.emplace(uri, map->_map.size() + 1); + const auto id = record.first->second; + if (record.second) { + assert(id == map->_map.size()); + assert(id == map->_unmap.size() + 1); + map->_unmap.emplace_back(std::move(uri)); + } + return id; } LV2_URID @@ -69,7 +78,7 @@ URIMap::URIDUnmapFeature::URIDUnmapFeature(URIMap* map, urid_unmap = *impl; } else { urid_unmap.unmap = default_unmap; - urid_unmap.handle = nullptr; + urid_unmap.handle = map; } } @@ -77,7 +86,12 @@ const char* URIMap::URIDUnmapFeature::default_unmap(LV2_URID_Unmap_Handle h, LV2_URID urid) { - return g_quark_to_string(urid); + URIMap* const map((URIMap*)h); + std::lock_guard lock(map->_mutex); + + return (urid > 0 && urid <= map->_unmap.size() + ? map->_unmap[urid - 1].c_str() + : NULL); } const char* -- cgit v1.2.1