summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cpp/include/Ice/FactoryTableDef.h19
-rw-r--r--cpp/src/Ice/FactoryTable.cpp50
-rw-r--r--cpp/src/Ice/FactoryTableDef.cpp56
3 files changed, 40 insertions, 85 deletions
diff --git a/cpp/include/Ice/FactoryTableDef.h b/cpp/include/Ice/FactoryTableDef.h
index 39c41a09a8d..c6df41b41f3 100644
--- a/cpp/include/Ice/FactoryTableDef.h
+++ b/cpp/include/Ice/FactoryTableDef.h
@@ -45,25 +45,6 @@ private:
OFTable _oft;
};
-class ICE_API FactoryTableWrapper : private IceUtil::noncopyable
-{
-public:
-
- friend class FactoryTable;
-
- FactoryTableWrapper();
- ~FactoryTableWrapper();
-
-private:
-
- void initialize();
- void finalize();
- static IceUtil::StaticMutex _m;
- static int _initCount;
-};
-
-extern ICE_API FactoryTableWrapper factoryTableWrapper;
-
}
#endif
diff --git a/cpp/src/Ice/FactoryTable.cpp b/cpp/src/Ice/FactoryTable.cpp
index 99ae9145596..75420dc4024 100644
--- a/cpp/src/Ice/FactoryTable.cpp
+++ b/cpp/src/Ice/FactoryTable.cpp
@@ -10,24 +10,54 @@
#include <Ice/FactoryTable.h>
#include <Ice/UserExceptionFactory.h>
+namespace IceInternal
+{
+
//
-// This constructor initializes the single global IceInternal::factoryTable instance
-// from the outside (if it hasn't been initialized yet). The constructor here
-// is triggered by a file-static instance of FactoryTable in each
-// slice2cpp-generated header file that uses non-local exceptions or non-abstract classes.
-// This ensures that IceInternal::factoryTable is always initialized before it is used.
+// Single global instance of the factory table for non-local
+// exceptions and non-abstract classes.
//
-IceInternal::FactoryTable::FactoryTable()
+ICE_DECLSPEC_EXPORT FactoryTableDef* factoryTable;
+
+}
+
+namespace
{
- IceInternal::factoryTableWrapper.initialize();
+static int initCount = 0; // Initialization count
+IceUtil::StaticMutex initCountMutex = ICE_STATIC_MUTEX_INITIALIZER;
+
+
+}
+
+//
+// This constructor initializes the single global
+// IceInternal::factoryTable instance from the outside (if it hasn't
+// been initialized yet). The constructor here is triggered by a
+// file-static instance of FactoryTable in each slice2cpp-generated
+// header file that uses non-local exceptions or non-abstract classes.
+// This ensures that IceInternal::factoryTable is always initialized
+// before it is used.
+//
+IceInternal::FactoryTable::FactoryTable()
+{
+ IceUtil::StaticMutex::Lock lock(initCountMutex);
+ if(0 == initCount++)
+ {
+ factoryTable = new FactoryTableDef;
+ }
}
//
-// Similarly, the destructor calls the finalize() method on the factory table wrapper which,
-// once the tables reference count drops to zero, deletes the table.
+// Similarly, the destructor calls the finalize() method on the
+// factory table wrapper which, once the tables reference count drops
+// to zero, deletes the table.
//
IceInternal::FactoryTable::~FactoryTable()
{
- IceInternal::factoryTableWrapper.finalize();
+ IceUtil::StaticMutex::Lock lock(initCountMutex);
+ if(0 == --initCount)
+ {
+ delete factoryTable;
+ }
}
diff --git a/cpp/src/Ice/FactoryTableDef.cpp b/cpp/src/Ice/FactoryTableDef.cpp
index 06d84cd8128..a217e3a996b 100644
--- a/cpp/src/Ice/FactoryTableDef.cpp
+++ b/cpp/src/Ice/FactoryTableDef.cpp
@@ -14,16 +14,6 @@
# include <dlfcn.h>
#endif
-namespace IceInternal
-{
-
-FactoryTableWrapper factoryTableWrapper; // Single global instance of the wrapper object that
- // initializes factoryTable.
-
-ICE_DECLSPEC_EXPORT FactoryTableDef* factoryTable; // Single global instance of the factory table for
- // non-local exceptions and non-abstract classes
-}
-
//
// Add a factory to the exception factory table.
// If the factory is present already, increment its reference count.
@@ -167,49 +157,3 @@ IceInternal::FactoryTableDef::removeObjectFactory(const std::string& t)
}
}
-//
-// The code generated by slice2cpp contains a file static instance of FactoryTable.
-// The constructor of FactoryTable calls initialize(), as does the constructor of
-// FactoryTableWrapper. This ensures that the global factoryTable variable is initialized
-// before it can be used, regardless of the order of initialization of global objects.
-//
-IceInternal::FactoryTableWrapper::FactoryTableWrapper()
-{
- initialize();
-}
-
-IceInternal::FactoryTableWrapper::~FactoryTableWrapper()
-{
- finalize();
-}
-
-//
-// Initialize the single global instance of the factory table, counting
-// the number of calls made.
-//
-void
-IceInternal::FactoryTableWrapper::initialize()
-{
- IceUtil::StaticMutex::Lock lock(_m);
- if(_initCount == 0)
- {
- factoryTable = new FactoryTableDef;
- }
- ++_initCount;
-}
-
-//
-// Delete the table if its reference count drops to zero.
-//
-void
-IceInternal::FactoryTableWrapper::finalize()
-{
- IceUtil::StaticMutex::Lock lock(_m);
- if(--_initCount == 0)
- {
- delete factoryTable;
- }
-}
-
-IceUtil::StaticMutex IceInternal::FactoryTableWrapper::_m = ICE_STATIC_MUTEX_INITIALIZER;
-int IceInternal::FactoryTableWrapper::_initCount = 0; // Initialization count