From bf0d8114c98cede767688be25b91d71abeb5262f Mon Sep 17 00:00:00 2001 From: tbeu Date: Sun, 10 Feb 2019 11:23:52 +0100 Subject: [PATCH] #525: Update comment and fix variable name --- include/exiv2/properties.hpp | 11 +++++++++-- src/properties.cpp | 16 ++++++++-------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/include/exiv2/properties.hpp b/include/exiv2/properties.hpp index 06238641..544e2cc0 100644 --- a/include/exiv2/properties.hpp +++ b/include/exiv2/properties.hpp @@ -195,8 +195,15 @@ namespace Exiv2 { */ static void unregisterNs(const std::string& ns); - //! lock to be used while modifying properties - static std::mutex rwLock_; + /*! + @brief Lock to be used while modifying properties. + + @todo For a proper read-write lock, this shall be improved by a + \em std::shared_timed_mutex (once C++14 is allowed) or + \em std::shared_mutex (once C++17 is allowed). The + read-access locks shall be updated to \em std::shared_lock then. + */ + static std::mutex mutex_; /*! @brief Unregister all custom namespaces. diff --git a/src/properties.cpp b/src/properties.cpp index 630748a8..0e8a5cb7 100644 --- a/src/properties.cpp +++ b/src/properties.cpp @@ -2476,11 +2476,11 @@ namespace Exiv2 { } XmpProperties::NsRegistry XmpProperties::nsRegistry_; - std::mutex XmpProperties::rwLock_; + std::mutex XmpProperties::mutex_; const XmpNsInfo* XmpProperties::lookupNsRegistry(const XmpNsInfo::Prefix& prefix) { - std::lock_guard scoped_read_lock(rwLock_); + std::lock_guard scoped_read_lock(mutex_); return lookupNsRegistryUnsafe(prefix); } @@ -2496,7 +2496,7 @@ namespace Exiv2 { void XmpProperties::registerNs(const std::string& ns, const std::string& prefix) { - std::lock_guard scoped_write_lock(rwLock_); + std::lock_guard scoped_write_lock(mutex_); std::string ns2 = ns; if ( ns2.substr(ns2.size() - 1, 1) != "/" && ns2.substr(ns2.size() - 1, 1) != "#") ns2 += "/"; @@ -2528,7 +2528,7 @@ namespace Exiv2 { void XmpProperties::unregisterNs(const std::string& ns) { - std::lock_guard scoped_write_lock(rwLock_); + std::lock_guard scoped_write_lock(mutex_); unregisterNsUnsafe(ns); } @@ -2544,7 +2544,7 @@ namespace Exiv2 { void XmpProperties::unregisterNs() { - std::lock_guard scoped_write_lock(rwLock_); + std::lock_guard scoped_write_lock(mutex_); NsRegistry::iterator i = nsRegistry_.begin(); while (i != nsRegistry_.end()) { NsRegistry::iterator kill = i++; @@ -2554,7 +2554,7 @@ namespace Exiv2 { std::string XmpProperties::prefix(const std::string& ns) { - std::lock_guard scoped_read_lock(rwLock_); + std::lock_guard scoped_read_lock(mutex_); std::string ns2 = ns; if ( ns2.substr(ns2.size() - 1, 1) != "/" && ns2.substr(ns2.size() - 1, 1) != "#") ns2 += "/"; @@ -2572,7 +2572,7 @@ namespace Exiv2 { std::string XmpProperties::ns(const std::string& prefix) { - std::lock_guard scoped_read_lock(rwLock_); + std::lock_guard scoped_read_lock(mutex_); const XmpNsInfo* xn = lookupNsRegistryUnsafe(XmpNsInfo::Prefix(prefix)); if (xn != 0) return xn->ns_; return nsInfoUnsafe(prefix)->ns_; @@ -2639,7 +2639,7 @@ namespace Exiv2 { const XmpNsInfo* XmpProperties::nsInfo(const std::string& prefix) { - std::lock_guard scoped_read_lock(rwLock_); + std::lock_guard scoped_read_lock(mutex_); return nsInfoUnsafe(prefix); }