Browse Source

Revert "[master] Avoid static destruction fiasco with InterprocessSyncFile and logger"

This reverts commit 34701adba7f7390640c70ba769cdb0b20f01f82c.
Mukund Sivaraman 12 years ago
parent
commit
7ffd1e0cad
2 changed files with 17 additions and 34 deletions
  1. 14 24
      src/lib/util/interprocess_sync_file.cc
  2. 3 10
      src/lib/util/interprocess_sync_file.h

+ 14 - 24
src/lib/util/interprocess_sync_file.cc

@@ -16,6 +16,9 @@
 
 
 #include <boost/weak_ptr.hpp>
 #include <boost/weak_ptr.hpp>
 
 
+#include <map>
+#include <string>
+
 #include <stdlib.h>
 #include <stdlib.h>
 #include <string.h>
 #include <string.h>
 #include <unistd.h>
 #include <unistd.h>
@@ -28,13 +31,21 @@ using namespace isc::util::thread;
 namespace isc {
 namespace isc {
 namespace util {
 namespace util {
 
 
+namespace { // unnamed namespace
+
+typedef std::map<std::string, boost::weak_ptr<Mutex> > SyncMap;
+
+Mutex sync_map_mutex;
+SyncMap sync_map;
+
+} // end of unnamed namespace
+
 InterprocessSyncFile::InterprocessSyncFile(const std::string& task_name) :
 InterprocessSyncFile::InterprocessSyncFile(const std::string& task_name) :
     InterprocessSync(task_name),
     InterprocessSync(task_name),
     fd_(-1)
     fd_(-1)
 {
 {
-    Mutex::Locker locker(getSyncMapMutex());
+    Mutex::Locker locker(sync_map_mutex);
 
 
-    SyncMap& sync_map = getSyncMap();
     SyncMap::iterator it = sync_map.find(task_name);
     SyncMap::iterator it = sync_map.find(task_name);
     if (it != sync_map.end()) {
     if (it != sync_map.end()) {
         mutex_ = it->second.lock();
         mutex_ = it->second.lock();
@@ -55,14 +66,13 @@ InterprocessSyncFile::~InterprocessSyncFile() {
         // it.
         // it.
     }
     }
 
 
-    Mutex::Locker locker(getSyncMapMutex());
+    Mutex::Locker locker(sync_map_mutex);
 
 
     // Unref the shared mutex.
     // Unref the shared mutex.
     locker_.reset();
     locker_.reset();
     mutex_.reset();
     mutex_.reset();
 
 
     // Remove name from the map if it is unused anymore.
     // Remove name from the map if it is unused anymore.
-    SyncMap& sync_map = getSyncMap();
     SyncMap::iterator it = sync_map.find(task_name_);
     SyncMap::iterator it = sync_map.find(task_name_);
     assert(it != sync_map.end());
     assert(it != sync_map.end());
 
 
@@ -74,26 +84,6 @@ InterprocessSyncFile::~InterprocessSyncFile() {
     // destruction when basic block is exited.
     // destruction when basic block is exited.
 }
 }
 
 
-InterprocessSyncFile::SyncMap&
-InterprocessSyncFile::getSyncMap() {
-    // avoid static destruction fiasco when the SyncMap is destroyed
-    // before clients which use it such as logger objects. This leaks,
-    // but isn't a growing leak.
-    static SyncMap* sync_map = new SyncMap;
-
-    return (*sync_map);
-}
-
-Mutex&
-InterprocessSyncFile::getSyncMapMutex() {
-    // avoid static destruction fiasco when the Mutex is destroyed
-    // before clients which use it such as logger objects. This leaks,
-    // but isn't a growing leak.
-    static Mutex* sync_map_mutex = new Mutex;
-
-    return (*sync_map_mutex);
-}
-
 bool
 bool
 InterprocessSyncFile::do_lock(int cmd, short l_type) {
 InterprocessSyncFile::do_lock(int cmd, short l_type) {
     // Open lock file only when necessary (i.e., here). This is so that
     // Open lock file only when necessary (i.e., here). This is so that

+ 3 - 10
src/lib/util/interprocess_sync_file.h

@@ -21,9 +21,6 @@
 
 
 #include <boost/shared_ptr.hpp>
 #include <boost/shared_ptr.hpp>
 
 
-#include <map>
-#include <string>
-
 namespace isc {
 namespace isc {
 namespace util {
 namespace util {
 
 
@@ -84,16 +81,12 @@ protected:
     bool unlock();
     bool unlock();
 
 
 private:
 private:
-    typedef boost::shared_ptr<isc::util::thread::Mutex> MutexPtr;
-    typedef boost::shared_ptr<isc::util::thread::Mutex::Locker> LockerPtr;
-    typedef std::map<std::string, boost::weak_ptr<isc::util::thread::Mutex> >
-        SyncMap;
-
-    SyncMap& getSyncMap();
-    isc::util::thread::Mutex& getSyncMapMutex();
     bool do_lock(int cmd, short l_type);
     bool do_lock(int cmd, short l_type);
 
 
     int fd_; ///< The descriptor for the open file
     int fd_; ///< The descriptor for the open file
+
+    typedef boost::shared_ptr<isc::util::thread::Mutex> MutexPtr;
+    typedef boost::shared_ptr<isc::util::thread::Mutex::Locker> LockerPtr;
     MutexPtr mutex_;   ///< A mutex for mutual exclusion among threads
     MutexPtr mutex_;   ///< A mutex for mutual exclusion among threads
     LockerPtr locker_; ///< A locker on mutex_
     LockerPtr locker_; ///< A locker on mutex_
 };
 };