summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordhinton <dhinton@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2002-06-05 14:18:47 +0000
committerdhinton <dhinton@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2002-06-05 14:18:47 +0000
commited1ce465b3b69ce01cbbd957b67b4e5e83bb03c6 (patch)
treef4e0fd54fc27386269cd7d6700023f7a0bcd9c9b
parentfdb975b46d8c827a8b2d372e4f687cc4859153d8 (diff)
downloadATCD-ed1ce465b3b69ce01cbbd957b67b4e5e83bb03c6.tar.gz
ChangeLogTag:Wed Jun 5 13:54:03 UTC 2002 Don Hinton <dhinton@ieee.org>
-rw-r--r--ChangeLog10
-rw-r--r--ChangeLogs/ChangeLog-02a10
-rw-r--r--ChangeLogs/ChangeLog-03a10
-rw-r--r--ace/DLL_Manager.cpp98
-rw-r--r--ace/DLL_Manager.h68
-rw-r--r--ace/Framework_Component.cpp3
6 files changed, 147 insertions, 52 deletions
diff --git a/ChangeLog b/ChangeLog
index f755e0b53f6..488d8d84c55 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+Wed Jun 5 13:54:03 UTC 2002 Don Hinton <dhinton@ieee.org>
+
+ * ace/DLL_Manager.{h,cpp}:
+ * ace/Framework_Component.cpp:
+
+ Made ACE_DLL_Manager a true singleton instead of using the
+ ACE_*Singleton templates, thus avoiding a problem with
+ multiple instantiations by broken compilers. Thanks to
+ Chris Kohlhoff <chris@kohloff.com> for this suggestion.
+
Wed Jun 5 08:33:25 2002 Douglas C. Schmidt <schmidt@tango.doc.wustl.edu>
* ace/Process_Manager.cpp (handle_signal): Added a check for
diff --git a/ChangeLogs/ChangeLog-02a b/ChangeLogs/ChangeLog-02a
index f755e0b53f6..488d8d84c55 100644
--- a/ChangeLogs/ChangeLog-02a
+++ b/ChangeLogs/ChangeLog-02a
@@ -1,3 +1,13 @@
+Wed Jun 5 13:54:03 UTC 2002 Don Hinton <dhinton@ieee.org>
+
+ * ace/DLL_Manager.{h,cpp}:
+ * ace/Framework_Component.cpp:
+
+ Made ACE_DLL_Manager a true singleton instead of using the
+ ACE_*Singleton templates, thus avoiding a problem with
+ multiple instantiations by broken compilers. Thanks to
+ Chris Kohlhoff <chris@kohloff.com> for this suggestion.
+
Wed Jun 5 08:33:25 2002 Douglas C. Schmidt <schmidt@tango.doc.wustl.edu>
* ace/Process_Manager.cpp (handle_signal): Added a check for
diff --git a/ChangeLogs/ChangeLog-03a b/ChangeLogs/ChangeLog-03a
index f755e0b53f6..488d8d84c55 100644
--- a/ChangeLogs/ChangeLog-03a
+++ b/ChangeLogs/ChangeLog-03a
@@ -1,3 +1,13 @@
+Wed Jun 5 13:54:03 UTC 2002 Don Hinton <dhinton@ieee.org>
+
+ * ace/DLL_Manager.{h,cpp}:
+ * ace/Framework_Component.cpp:
+
+ Made ACE_DLL_Manager a true singleton instead of using the
+ ACE_*Singleton templates, thus avoiding a problem with
+ multiple instantiations by broken compilers. Thanks to
+ Chris Kohlhoff <chris@kohloff.com> for this suggestion.
+
Wed Jun 5 08:33:25 2002 Douglas C. Schmidt <schmidt@tango.doc.wustl.edu>
* ace/Process_Manager.cpp (handle_signal): Added a check for
diff --git a/ace/DLL_Manager.cpp b/ace/DLL_Manager.cpp
index af7984b43c7..2db68422761 100644
--- a/ace/DLL_Manager.cpp
+++ b/ace/DLL_Manager.cpp
@@ -9,6 +9,7 @@
#include "ace/OS.h"
#include "ace/Lib_Find.h"
+#include "ace/Object_Manager.h"
ACE_RCSID(ace, DLL, "$Id$")
@@ -107,7 +108,8 @@ ACE_DLL_Handle::open (const ACE_TCHAR *dll_name,
if (this->handle_ == ACE_SHLIB_INVALID_HANDLE)
{
ACE_ERROR_RETURN ((LM_ERROR,
- ACE_LIB_TEXT ("ACE_DLL_Manager_Ex::open: Invalid handle: %s\n"), this->error ()->c_str ()),
+ ACE_LIB_TEXT ("ACE_DLL_Manager_Ex::open: Invalid handle: %s\n"),
+ this->error ()->c_str ()),
-1);
}
}
@@ -227,36 +229,73 @@ ACE_DLL_Handle::error (void)
/******************************************************************/
-ACE_DLL_Manager_Ex::ACE_DLL_Manager_Ex (int size)
+// Pointer to the Singleton instance.
+ACE_DLL_Manager *ACE_DLL_Manager::instance_ = 0;
+
+
+ACE_DLL_Manager *
+ACE_DLL_Manager::instance (int size)
+{
+ ACE_TRACE ("ACE_DLL_Manager::instance");
+
+ if (ACE_DLL_Manager::instance_ == 0)
+ {
+ // Perform Double-Checked Locking Optimization.
+ ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon,
+ *ACE_Static_Object_Lock::instance (), 0));
+ if (ACE_DLL_Manager::instance_ == 0)
+ {
+ ACE_NEW_RETURN (ACE_DLL_Manager::instance_,
+ ACE_DLL_Manager (size),
+ 0);
+ }
+ }
+
+ return ACE_DLL_Manager::instance_;
+}
+
+void
+ACE_DLL_Manager::close_singleton (void)
+{
+ ACE_TRACE ("ACE_DLL_Manager::close_singleton");
+
+ ACE_MT (ACE_GUARD (ACE_Recursive_Thread_Mutex, ace_mon,
+ *ACE_Static_Object_Lock::instance ()));
+
+ delete ACE_DLL_Manager::instance_;
+ ACE_DLL_Manager::instance_ = 0;
+}
+
+ACE_DLL_Manager::ACE_DLL_Manager (int size)
: handle_vector_ (0),
current_size_ (0),
total_size_ (0),
unload_policy_ (ACE_DLL_UNLOAD_POLICY_PER_DLL)
{
- ACE_TRACE ("ACE_DLL_Manager_Ex::ACE_DLL_Manager_Ex");
+ ACE_TRACE ("ACE_DLL_Manager::ACE_DLL_Manager");
if (this->open (size) != 0)
ACE_ERROR ((LM_ERROR,
- ACE_LIB_TEXT ("ACE_DLL_Manager_Ex ctor failed to allocate ")
+ ACE_LIB_TEXT ("ACE_DLL_Manager ctor failed to allocate ")
ACE_LIB_TEXT ("handle_vector_.\n")));
}
-ACE_DLL_Manager_Ex::~ACE_DLL_Manager_Ex (void)
+ACE_DLL_Manager::~ACE_DLL_Manager (void)
{
- ACE_TRACE ("ACE_DLL_Manager_Ex::~ACE_DLL_Manager_Ex");
+ ACE_TRACE ("ACE_DLL_Manager::~ACE_DLL_Manager");
if (this->close () != 0)
ACE_ERROR ((LM_ERROR,
- ACE_LIB_TEXT ("ACE_DLL_Manager_Ex dtor failed to close ")
+ ACE_LIB_TEXT ("ACE_DLL_Manager dtor failed to close ")
ACE_LIB_TEXT ("properly.\n")));
}
ACE_DLL_Handle *
-ACE_DLL_Manager_Ex::open_dll (const ACE_TCHAR *dll_name,
- int open_mode,
- ACE_SHLIB_HANDLE handle)
+ACE_DLL_Manager::open_dll (const ACE_TCHAR *dll_name,
+ int open_mode,
+ ACE_SHLIB_HANDLE handle)
{
- ACE_TRACE ("ACE_DLL_Manager_Ex::open_dll");
+ ACE_TRACE ("ACE_DLL_Manager::open_dll");
ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, 0));
ACE_DLL_Handle *dll_handle = this->find_dll (dll_name);
@@ -289,9 +328,9 @@ ACE_DLL_Manager_Ex::open_dll (const ACE_TCHAR *dll_name,
}
int
-ACE_DLL_Manager_Ex::close_dll (const ACE_TCHAR *dll_name)
+ACE_DLL_Manager::close_dll (const ACE_TCHAR *dll_name)
{
- ACE_TRACE ("ACE_DLL_Manager_Ex::close_dll");
+ ACE_TRACE ("ACE_DLL_Manager::close_dll");
ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, 0));
ACE_DLL_Handle *handle = this->find_dll (dll_name);
@@ -304,16 +343,16 @@ ACE_DLL_Manager_Ex::close_dll (const ACE_TCHAR *dll_name)
}
u_long
-ACE_DLL_Manager_Ex::unload_policy (void) const
+ACE_DLL_Manager::unload_policy (void) const
{
- ACE_TRACE ("ACE_DLL_Manager_Ex::unload_policy");
+ ACE_TRACE ("ACE_DLL_Manager::unload_policy");
return this->unload_policy_;
}
void
-ACE_DLL_Manager_Ex::unload_policy (u_long unload_policy)
+ACE_DLL_Manager::unload_policy (u_long unload_policy)
{
- ACE_TRACE ("ACE_DLL_Manager_Ex::unload_policy");
+ ACE_TRACE ("ACE_DLL_Manager::unload_policy");
ACE_MT (ACE_GUARD (ACE_Thread_Mutex, ace_mon, this->lock_));
u_long old_policy = this->unload_policy_;
@@ -339,9 +378,9 @@ ACE_DLL_Manager_Ex::unload_policy (u_long unload_policy)
}
int
-ACE_DLL_Manager_Ex::open (int size)
+ACE_DLL_Manager::open (int size)
{
- ACE_TRACE ("ACE_DLL_Manager_Ex::open");
+ ACE_TRACE ("ACE_DLL_Manager::open");
ACE_DLL_Handle **temp;
@@ -355,9 +394,9 @@ ACE_DLL_Manager_Ex::open (int size)
}
int
-ACE_DLL_Manager_Ex::close (void)
+ACE_DLL_Manager::close (void)
{
- ACE_TRACE ("ACE_DLL_Manager_Ex::close");
+ ACE_TRACE ("ACE_DLL_Manager::close");
int force_close = 1;
@@ -384,9 +423,9 @@ ACE_DLL_Manager_Ex::close (void)
}
ACE_DLL_Handle *
-ACE_DLL_Manager_Ex::find_dll (const ACE_TCHAR *dll_name) const
+ACE_DLL_Manager::find_dll (const ACE_TCHAR *dll_name) const
{
- ACE_TRACE ("ACE_DLL_Manager_Ex::find_dll");
+ ACE_TRACE ("ACE_DLL_Manager::find_dll");
int i;
for (i = 0; i < this->current_size_; i++)
@@ -400,9 +439,9 @@ ACE_DLL_Manager_Ex::find_dll (const ACE_TCHAR *dll_name) const
}
int
-ACE_DLL_Manager_Ex::unload_dll (ACE_DLL_Handle *dll_handle, int force_unload)
+ACE_DLL_Manager::unload_dll (ACE_DLL_Handle *dll_handle, int force_unload)
{
- ACE_TRACE ("ACE_DLL_Manager_Ex::unload_dll");
+ ACE_TRACE ("ACE_DLL_Manager::unload_dll");
if (dll_handle)
{
@@ -438,20 +477,15 @@ ACE_DLL_Manager_Ex::unload_dll (ACE_DLL_Handle *dll_handle, int force_unload)
if (dll_handle->close (unload) != 0)
ACE_ERROR_RETURN ((LM_ERROR,
- ACE_LIB_TEXT ("ACE_DLL_Manager_Ex::unload error.\n")),
+ ACE_LIB_TEXT ("ACE_DLL_Manager::unload error.\n")),
-1);
}
else
ACE_ERROR_RETURN ((LM_ERROR,
- ACE_LIB_TEXT ("ACE_DLL_Manager_Ex::unload_dll called with ")
+ ACE_LIB_TEXT ("ACE_DLL_Manager::unload_dll called with ")
ACE_LIB_TEXT ("null pointer.\n")),
-1);
return 0;
}
-#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
-template class ACE_Unmanaged_Singleton< ACE_DLL_Manager_Ex, ACE_SYNCH_MUTEX >;
-#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
-#pragma instantiate ACE_Unmanaged_Singleton< ACE_DLL_Manager_Ex, ACE_SYNCH_MUTEX >
-#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */
diff --git a/ace/DLL_Manager.h b/ace/DLL_Manager.h
index a78b7a732b8..200fe4475ba 100644
--- a/ace/DLL_Manager.h
+++ b/ace/DLL_Manager.h
@@ -16,7 +16,6 @@
#include "ace/pre.h"
#include "ace/OS.h"
-#include "ace/Singleton.h"
#include "ace/Synch_T.h"
#include "ace/Auto_Ptr.h"
#include "ace/SString.h"
@@ -130,29 +129,55 @@ private:
};
+class ACE_Framework_Repository;
/**
- * @class ACE_DLL_Manager_Ex
+ * @class ACE_DLL_Manager
*
- * @brief This class serves as a factory and repository for
- * instances of ACE_DLL_Handle. It is implemented and typedef'd
- * as a singleton, ACE_DLL_Manager, and is thus always available
- * via it's instance() method.
+ * @brief This class is a singleton and serves as a factory and
+ * repository for instances of ACE_DLL_Handle.
+ *
+ * This class is a singleton whose lifetime is managed by the
+ * ACE_Framework_Repository. Although it is normally meant to be
+ * used directly only by ACE_DLL, applications can call the unload_policy()
+ * methods in order get/set the the dll unload policy. Unload policies include
+ * per_process/per-dll and eager/lazy. Dlls can export set their own policy
+ * by using the ACE_DLL_UNLOAD_POLICY macro found in config-all.h. If a dll
+ * choses to set an unload policy, it will be used when the per-dll policy
+ * (the default) is in effect. If the per-dll policy is in effect and a dll
+ * has not chosen to set a policy, the current per-process policy will be
+ * used.
+ *
+ * The following policy macros are provided in config-all.h:
+ *
+ * ACE_DLL_UNLOAD_POLICY_PER_PROCESS - Per-process policy that unloads dlls
+ * eagerly.
+ *
+ * ACE_DLL_UNLOAD_POLICY_PER_DLL - Apply policy on a per-dll basis. If the
+ * dll doesn't use one of the macros below, the current per-process policy
+ * will be used.
+ *
+ * ACE_DLL_UNLOAD_POLICY_LAZY - Don't unload dll when refcount reaches
+ * zero, i.e., wait for either an explicit unload request or program exit.
+ *
+ * ACE_DLL_UNLOAD_POLICY_DEFAULT - Default policy allows dlls to control
+ * their own destinies, but will unload those that don't make a choice eagerly.
*
*/
-class ACE_Export ACE_DLL_Manager_Ex
+class ACE_Export ACE_DLL_Manager
{
public:
+ // This if to silence the compiler warnings, even though ACE_Framework_Repository
+ // always uses the instance method.
+ friend ACE_Framework_Repository;
+
enum
{
DEFAULT_SIZE = ACE_DEFAULT_DLL_MANAGER_SIZE
};
- /// Default constructor.
- ACE_DLL_Manager_Ex (int size = ACE_DLL_Manager_Ex::DEFAULT_SIZE);
-
- /// Destructor.
- ~ACE_DLL_Manager_Ex (void);
+ /// Return a unique instance
+ static ACE_DLL_Manager *instance (int size = ACE_DLL_Manager::DEFAULT_SIZE);
/// Factory for ACE_DLL_Handle objects. If one already exits,
/// its refcount is incremented.
@@ -185,6 +210,14 @@ protected:
int unload_dll (ACE_DLL_Handle *dll_handle, int force_unload = 0);
private:
+ /// Default constructor.
+ ACE_DLL_Manager (int size = ACE_DLL_Manager::DEFAULT_SIZE);
+
+ /// Destructor.
+ ~ACE_DLL_Manager (void);
+
+ /// Close the singleton instance.
+ static void close_singleton (void);
/// Vector containing all loaded handle objects.
ACE_DLL_Handle **handle_vector_;
@@ -198,19 +231,18 @@ private:
/// Unload strategy.
u_long unload_policy_;
+ /// Pointer to a process-wide <ACE_DLL_Manager>.
+ static ACE_DLL_Manager *instance_;
+
#if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
/// Synchronization variable for the MT_SAFE Repository
ACE_Thread_Mutex lock_;
#endif /* ACE_MT_SAFE */
// = Disallow copying and assignment since we don't handle these.
- ACE_UNIMPLEMENTED_FUNC (ACE_DLL_Manager_Ex (const ACE_DLL_Manager_Ex &))
- ACE_UNIMPLEMENTED_FUNC (void operator= (const ACE_DLL_Manager_Ex &))
+ ACE_UNIMPLEMENTED_FUNC (ACE_DLL_Manager (const ACE_DLL_Manager &))
+ ACE_UNIMPLEMENTED_FUNC (void operator= (const ACE_DLL_Manager &))
};
-/// Global singleton.
-typedef ACE_Unmanaged_Singleton < ACE_DLL_Manager_Ex,
- ACE_SYNCH_MUTEX > ACE_DLL_Manager;
-
#include "ace/post.h"
#endif /* ACE_DLL_MANAGER_H */
diff --git a/ace/Framework_Component.cpp b/ace/Framework_Component.cpp
index 5f2e9c14b1c..4484fc930cf 100644
--- a/ace/Framework_Component.cpp
+++ b/ace/Framework_Component.cpp
@@ -80,8 +80,7 @@ ACE_Framework_Repository::close (void)
this->current_size_ = 0;
}
- ACE_DLL_Manager::close ();
-
+ ACE_DLL_Manager::close_singleton ();
return 0;
}