From 261170cc5b6661106877dc2611dab281f4d91348 Mon Sep 17 00:00:00 2001 From: Adrian Kummerländer Date: Sat, 3 May 2014 22:04:16 +0200 Subject: Revamped DomDocumentCache with regard to thread safety * DomDocumentCache::item class now is _finalized_ by default and doesn't perform document instantiation, just lifetime management ** xercesc::DOMDocument is instantiated inside the external function implementations and committed to the document cache for conversion to a xalan document * added mutex with scoped lock to prevent concurrent write access to the std::unordered_map contained withing DomDocumentCache * functionality of the _get_ member method was split into _get_ and _create_ ** added typedef for std::pair specialization type "optional_item" that functions as the return value of _create_ and _get_ * "locator->getSystemId()" was leaking memory as xerces doesn't manage the lifetime of the returned heap-allocated char array ** analog to XMLCh* strings ** transformed XercesStringGuard into template class to be instantiated on either XMLCh or char --- src/support/dom/document_cache.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/support/dom/document_cache.h') diff --git a/src/support/dom/document_cache.h b/src/support/dom/document_cache.h index 287a316..af99102 100644 --- a/src/support/dom/document_cache.h +++ b/src/support/dom/document_cache.h @@ -1,8 +1,11 @@ #ifndef INPUTXSLT_SRC_SUPPORT_DOM_DOCUMENT_CACHE_H_ #define INPUTXSLT_SRC_SUPPORT_DOM_DOCUMENT_CACHE_H_ -#include +#include + #include +#include +#include #include namespace InputXSLT { @@ -10,12 +13,15 @@ namespace InputXSLT { class DomDocumentCache { public: class item; + typedef std::pair optional_item; DomDocumentCache(); - item* get(const std::string&); + optional_item get(const std::string&); + optional_item create(const std::string&, xercesc::DOMDocument*); private: + std::mutex write_mutex_; std::unordered_map> map_; }; -- cgit v1.2.3