aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-08-12 14:48:53 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-08-12 14:48:53 +0000
commit99a0f997ec340d6d752cc5908bebce05f85936b6 (patch)
treeec55d75c68aa8394b274d53906918e372c18ccd7
parent010b197cd525f6049fcdf630fb02a7e973a31a2d (diff)
downloadpaludis-99a0f997ec340d6d752cc5908bebce05f85936b6.tar.gz
paludis-99a0f997ec340d6d752cc5908bebce05f85936b6.tar.xz
Thread safety
-rw-r--r--paludis/repositories/e/glsa.cc31
1 files changed, 18 insertions, 13 deletions
diff --git a/paludis/repositories/e/glsa.cc b/paludis/repositories/e/glsa.cc
index 2f9ed2a..c0ef136 100644
--- a/paludis/repositories/e/glsa.cc
+++ b/paludis/repositories/e/glsa.cc
@@ -189,6 +189,7 @@ namespace
{
struct LibXMLHandle
{
+ Mutex mutex;
void * handle;
tr1::shared_ptr<GLSA> (* create_glsa_from_xml_file_handle)(const std::string &);
@@ -216,19 +217,23 @@ GLSA::create_from_xml_file(const std::string & filename)
# ifdef MONOLITHIC
# else
- if (0 == libxmlhandle.handle)
- libxmlhandle.handle = dlopen("libpaludiserepositoryxmlthings.so",
- RTLD_NOW | RTLD_GLOBAL);
- if (0 == libxmlhandle.handle)
- throw NotAvailableError("Cannot create GLSA from XML file '" + filename + "' due to error '"
- + stringify(dlerror()) + "' when dlopen(libpaludiserepositoryxmlthings.so)");
-
- if (0 == libxmlhandle.create_glsa_from_xml_file_handle)
- libxmlhandle.create_glsa_from_xml_file_handle = STUPID_CAST(tr1::shared_ptr<GLSA> (*)(const std::string &),
- dlsym(libxmlhandle.handle, "create_glsa_from_xml_file"));
- if (0 == libxmlhandle.create_glsa_from_xml_file_handle)
- throw NotAvailableError("Cannot create GLSA from XML file '" + filename + "' due to error '"
- + stringify(dlerror()) + "' when dlsym(libpaludisgentoorepositoryxmlthings.so, create_glsa_from_xml_file)");
+ {
+ Lock lock(libxmlhandle.mutex);
+
+ if (0 == libxmlhandle.handle)
+ libxmlhandle.handle = dlopen("libpaludiserepositoryxmlthings.so",
+ RTLD_NOW | RTLD_GLOBAL);
+ if (0 == libxmlhandle.handle)
+ throw NotAvailableError("Cannot create GLSA from XML file '" + filename + "' due to error '"
+ + stringify(dlerror()) + "' when dlopen(libpaludiserepositoryxmlthings.so)");
+
+ if (0 == libxmlhandle.create_glsa_from_xml_file_handle)
+ libxmlhandle.create_glsa_from_xml_file_handle = STUPID_CAST(tr1::shared_ptr<GLSA> (*)(const std::string &),
+ dlsym(libxmlhandle.handle, "create_glsa_from_xml_file"));
+ if (0 == libxmlhandle.create_glsa_from_xml_file_handle)
+ throw NotAvailableError("Cannot create GLSA from XML file '" + filename + "' due to error '"
+ + stringify(dlerror()) + "' when dlsym(libpaludisgentoorepositoryxmlthings.so, create_glsa_from_xml_file)");
+ }
# endif
#else