From: Mukund Sivaraman Date: Tue, 16 Oct 2012 19:28:31 +0000 (+0530) Subject: Revert "[master] Avoid static destruction fiasco with InterprocessSyncFile and logger" X-Git-Tag: trac2402_base~24 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7ffd1e0cad3bd125b490953dbea9f22c67e40fae;p=thirdparty%2Fkea.git Revert "[master] Avoid static destruction fiasco with InterprocessSyncFile and logger" This reverts commit 34701adba7f7390640c70ba769cdb0b20f01f82c. --- diff --git a/src/lib/util/interprocess_sync_file.cc b/src/lib/util/interprocess_sync_file.cc index 509a19c7c2..6da3f146d6 100644 --- a/src/lib/util/interprocess_sync_file.cc +++ b/src/lib/util/interprocess_sync_file.cc @@ -16,6 +16,9 @@ #include +#include +#include + #include #include #include @@ -28,13 +31,21 @@ using namespace isc::util::thread; namespace isc { namespace util { +namespace { // unnamed namespace + +typedef std::map > SyncMap; + +Mutex sync_map_mutex; +SyncMap sync_map; + +} // end of unnamed namespace + InterprocessSyncFile::InterprocessSyncFile(const std::string& task_name) : InterprocessSync(task_name), fd_(-1) { - Mutex::Locker locker(getSyncMapMutex()); + Mutex::Locker locker(sync_map_mutex); - SyncMap& sync_map = getSyncMap(); SyncMap::iterator it = sync_map.find(task_name); if (it != sync_map.end()) { mutex_ = it->second.lock(); @@ -55,14 +66,13 @@ InterprocessSyncFile::~InterprocessSyncFile() { // it. } - Mutex::Locker locker(getSyncMapMutex()); + Mutex::Locker locker(sync_map_mutex); // Unref the shared mutex. locker_.reset(); mutex_.reset(); // Remove name from the map if it is unused anymore. - SyncMap& sync_map = getSyncMap(); SyncMap::iterator it = sync_map.find(task_name_); assert(it != sync_map.end()); @@ -74,26 +84,6 @@ InterprocessSyncFile::~InterprocessSyncFile() { // 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 InterprocessSyncFile::do_lock(int cmd, short l_type) { // Open lock file only when necessary (i.e., here). This is so that diff --git a/src/lib/util/interprocess_sync_file.h b/src/lib/util/interprocess_sync_file.h index 6f7da014af..5cb64c1c05 100644 --- a/src/lib/util/interprocess_sync_file.h +++ b/src/lib/util/interprocess_sync_file.h @@ -21,9 +21,6 @@ #include -#include -#include - namespace isc { namespace util { @@ -84,16 +81,12 @@ protected: bool unlock(); private: - typedef boost::shared_ptr MutexPtr; - typedef boost::shared_ptr LockerPtr; - typedef std::map > - SyncMap; - - SyncMap& getSyncMap(); - isc::util::thread::Mutex& getSyncMapMutex(); bool do_lock(int cmd, short l_type); int fd_; ///< The descriptor for the open file + + typedef boost::shared_ptr MutexPtr; + typedef boost::shared_ptr LockerPtr; MutexPtr mutex_; ///< A mutex for mutual exclusion among threads LockerPtr locker_; ///< A locker on mutex_ };