Commit 0caaf237 by Maarten L. Hekkelman

Thread local compound factory, for servers that manipulate the factory.

parent c5676f1d
...@@ -5,7 +5,6 @@ obj/ ...@@ -5,7 +5,6 @@ obj/
.pc/ .pc/
autom4te.cache/ autom4te.cache/
GNUmakefile GNUmakefile
include/src/Config.hpp
tools/symop-map-generator tools/symop-map-generator
test/unit-test test/unit-test
libcifpp.pc libcifpp.pc
...@@ -14,3 +13,8 @@ config.status ...@@ -14,3 +13,8 @@ config.status
config.log config.log
libtool libtool
test/pdb2cif-test test/pdb2cif-test
src/revision.hpp
src/Config.hpp.in~
src/Config.hpp
aclocal.m4
version-info-*.txt
...@@ -16964,8 +16964,8 @@ ac_compiler_gnu=$ac_cv_cxx_compiler_gnu ...@@ -16964,8 +16964,8 @@ ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
LIBCIF_CURRENT=1 LIBCIF_CURRENT=1
LIBCIF_REVISION=0 LIBCIF_REVISION=1
LIBCIF_AGE=0 LIBCIF_AGE=1
LIBCIF_LT_CURRENT="${LIBCIF_CURRENT}" LIBCIF_LT_CURRENT="${LIBCIF_CURRENT}"
LIBCIF_LT_VERSION="${LIBCIF_CURRENT}:${LIBCIF_REVISION}:${LIBCIF_AGE}" LIBCIF_LT_VERSION="${LIBCIF_CURRENT}:${LIBCIF_REVISION}:${LIBCIF_AGE}"
...@@ -16973,7 +16973,7 @@ LIBCIF_LT_VERSION="${LIBCIF_CURRENT}:${LIBCIF_REVISION}:${LIBCIF_AGE}" ...@@ -16973,7 +16973,7 @@ LIBCIF_LT_VERSION="${LIBCIF_CURRENT}:${LIBCIF_REVISION}:${LIBCIF_AGE}"
LIBCIF_SEMANTIC_VERSION=1.0.0 LIBCIF_SEMANTIC_VERSION=1.1.0
......
...@@ -310,7 +310,9 @@ class CompoundFactory ...@@ -310,7 +310,9 @@ class CompoundFactory
{ {
public: public:
static void init(bool useThreadLocalInstanceOnly);
static CompoundFactory& instance(); static CompoundFactory& instance();
static void clear();
void pushDictionary(const std::string& inDictFile); void pushDictionary(const std::string& inDictFile);
void popDictionary(); void popDictionary();
...@@ -326,15 +328,18 @@ class CompoundFactory ...@@ -326,15 +328,18 @@ class CompoundFactory
const Link* getLink(std::string id); const Link* getLink(std::string id);
const Link* createLink(std::string id); const Link* createLink(std::string id);
~CompoundFactory();
private: private:
CompoundFactory(); CompoundFactory();
~CompoundFactory();
CompoundFactory(const CompoundFactory&) = delete; CompoundFactory(const CompoundFactory&) = delete;
CompoundFactory& operator=(const CompoundFactory&) = delete; CompoundFactory& operator=(const CompoundFactory&) = delete;
static CompoundFactory* sInstance; static CompoundFactory* sInstance;
static thread_local std::unique_ptr<CompoundFactory> tlInstance;
static bool sUseThreadLocalInstance;
class CompoundFactoryImpl* mImpl; class CompoundFactoryImpl* mImpl;
}; };
......
...@@ -1247,6 +1247,13 @@ const Link* CompoundFactoryImpl::createLink(std::string id) ...@@ -1247,6 +1247,13 @@ const Link* CompoundFactoryImpl::createLink(std::string id)
// -------------------------------------------------------------------- // --------------------------------------------------------------------
CompoundFactory* CompoundFactory::sInstance; CompoundFactory* CompoundFactory::sInstance;
thread_local std::unique_ptr<CompoundFactory> CompoundFactory::tlInstance;
bool CompoundFactory::sUseThreadLocalInstance;
void CompoundFactory::init(bool useThreadLocalInstanceOnly)
{
sUseThreadLocalInstance = useThreadLocalInstanceOnly;
}
CompoundFactory::CompoundFactory() CompoundFactory::CompoundFactory()
: mImpl(nullptr) : mImpl(nullptr)
...@@ -1275,9 +1282,29 @@ CompoundFactory::~CompoundFactory() ...@@ -1275,9 +1282,29 @@ CompoundFactory::~CompoundFactory()
CompoundFactory& CompoundFactory::instance() CompoundFactory& CompoundFactory::instance()
{ {
if (sInstance == nullptr) if (sUseThreadLocalInstance)
sInstance = new CompoundFactory(); {
return *sInstance; if (not tlInstance)
tlInstance.reset(new CompoundFactory());
return *tlInstance;
}
else
{
if (sInstance == nullptr)
sInstance = new CompoundFactory();
return *sInstance;
}
}
void CompoundFactory::clear()
{
if (sUseThreadLocalInstance)
tlInstance.reset(nullptr);
else
{
delete sInstance;
sInstance = nullptr;
}
} }
void CompoundFactory::pushDictionary(const std::string& inDictFile) void CompoundFactory::pushDictionary(const std::string& inDictFile)
...@@ -1340,6 +1367,6 @@ bool CompoundFactory::isKnownBase(const std::string& resName) const ...@@ -1340,6 +1367,6 @@ bool CompoundFactory::isKnownBase(const std::string& resName) const
std::string CompoundFactory::unalias(const std::string& resName) const std::string CompoundFactory::unalias(const std::string& resName) const
{ {
return mImpl->unalias(resName); return mImpl->unalias(resName);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment