]> granicus.if.org Git - pdns/commitdiff
add initlock in lmdb backend
authorKees Monshouwer <mind04@monshouwer.org>
Sat, 13 Sep 2014 10:37:01 +0000 (12:37 +0200)
committermind04 <mind04@monshouwer.org>
Sat, 13 Sep 2014 10:37:01 +0000 (12:37 +0200)
modules/lmdbbackend/lmdbbackend.cc
modules/lmdbbackend/lmdbbackend.hh

index 080d747dcc6c8563d557744cd102d1fd7b7d7caa..fe302aab2bf887f299c1054220e51842900a4a34 100644 (file)
@@ -22,6 +22,7 @@
 #include "lmdbbackend.hh"
 #include <pdns/arguments.hh>
 #include <pdns/base32.hh>
+#include <pdns/lock.hh>
 
 #if 0
 #define DEBUGLOG(msg) L<<Logger::Error<<msg
@@ -29,6 +30,8 @@
 #define DEBUGLOG(msg) do {} while(0)
 #endif
 
+pthread_mutex_t LMDBBackend::s_initlock = PTHREAD_MUTEX_INITIALIZER;
+
 LMDBBackend::LMDBBackend(const string &suffix)
 {
     setArgPrefix("lmdb"+suffix);
@@ -52,6 +55,8 @@ void LMDBBackend::open_db() {
     if( MDB_VERINT( major, minor, patch ) < MDB_VERINT( 0, 9, 8 ) )
         throw PDNSException( "LMDB Library version too old (" + verstring + "). Needs to be 0.9.8 or greater" );
 
+    Lock l(&s_initlock);
+
     if( (rc = mdb_env_create(&env))  )
         throw PDNSException("Couldn't open LMDB database " + path + ": mdb_env_create() returned " + mdb_strerror(rc));
 
index 52367717e65d85754bee269faf5cf97fd76f7d89..aeaa2765a513d5d208beeae3b126a3c037eae769 100644 (file)
@@ -4,6 +4,7 @@
  */
 
 #include <lmdb.h>
+#include <pthread.h>
 #include <pdns/dnsbackend.hh>
 
 class LMDBBackend : public DNSReversedBackend
@@ -39,6 +40,7 @@ private:
     void open_db();
     void close_db();
     inline bool get_finished();
+    static pthread_mutex_t s_initlock;
 
 public:
     LMDBBackend(const string &suffix="");