Commit 0caaf237 by Maarten L. Hekkelman

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

parent c5676f1d
......@@ -5,7 +5,6 @@ obj/
.pc/
autom4te.cache/
GNUmakefile
include/src/Config.hpp
tools/symop-map-generator
test/unit-test
libcifpp.pc
......@@ -14,3 +13,8 @@ config.status
config.log
libtool
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
LIBCIF_CURRENT=1
LIBCIF_REVISION=0
LIBCIF_AGE=0
LIBCIF_REVISION=1
LIBCIF_AGE=1
LIBCIF_LT_CURRENT="${LIBCIF_CURRENT}"
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
{
public:
static void init(bool useThreadLocalInstanceOnly);
static CompoundFactory& instance();
static void clear();
void pushDictionary(const std::string& inDictFile);
void popDictionary();
......@@ -326,15 +328,18 @@ class CompoundFactory
const Link* getLink(std::string id);
const Link* createLink(std::string id);
~CompoundFactory();
private:
CompoundFactory();
~CompoundFactory();
CompoundFactory(const CompoundFactory&) = delete;
CompoundFactory& operator=(const CompoundFactory&) = delete;
static CompoundFactory* sInstance;
static thread_local std::unique_ptr<CompoundFactory> tlInstance;
static bool sUseThreadLocalInstance;
class CompoundFactoryImpl* mImpl;
};
......
......@@ -1247,6 +1247,13 @@ const Link* CompoundFactoryImpl::createLink(std::string id)
// --------------------------------------------------------------------
CompoundFactory* CompoundFactory::sInstance;
thread_local std::unique_ptr<CompoundFactory> CompoundFactory::tlInstance;
bool CompoundFactory::sUseThreadLocalInstance;
void CompoundFactory::init(bool useThreadLocalInstanceOnly)
{
sUseThreadLocalInstance = useThreadLocalInstanceOnly;
}
CompoundFactory::CompoundFactory()
: mImpl(nullptr)
......@@ -1275,9 +1282,29 @@ CompoundFactory::~CompoundFactory()
CompoundFactory& CompoundFactory::instance()
{
if (sInstance == nullptr)
sInstance = new CompoundFactory();
return *sInstance;
if (sUseThreadLocalInstance)
{
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)
......@@ -1340,6 +1367,6 @@ bool CompoundFactory::isKnownBase(const std::string& resName) const
std::string CompoundFactory::unalias(const std::string& resName) const
{
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