diff options
author | dhinton <dhinton@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2003-12-18 22:56:52 +0000 |
---|---|---|
committer | dhinton <dhinton@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2003-12-18 22:56:52 +0000 |
commit | f0a4a90cd04ef8c99c34f16338d75843a8245cb4 (patch) | |
tree | e3742043e6870ea1e3cc8c14fac9d2ecd961b747 | |
parent | 2bc6e22c1cf1c5760ddf15d79d0ffe11b5453dd7 (diff) | |
download | ATCD-f0a4a90cd04ef8c99c34f16338d75843a8245cb4.tar.gz |
ChangeLogTag:Thu Dec 18 22:43:09 UTC 2003 Don Hinton <dhinton@dresystems.com>
-rw-r--r-- | ChangeLog | 15 | ||||
-rw-r--r-- | ace/Malloc_T.cpp | 39 | ||||
-rw-r--r-- | ace/Malloc_T.h | 24 | ||||
-rw-r--r-- | ace/Process_Semaphore.cpp | 17 | ||||
-rw-r--r-- | ace/Process_Semaphore.h | 20 | ||||
-rw-r--r-- | ace/Thread_Semaphore.cpp | 17 | ||||
-rw-r--r-- | ace/Thread_Semaphore.h | 20 |
7 files changed, 141 insertions, 11 deletions
diff --git a/ChangeLog b/ChangeLog index 46a6d49650d..6e93c49180d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +Thu Dec 18 22:43:09 UTC 2003 Don Hinton <dhinton@dresystems.com> + + * ace/Malloc_T.{h,cpp}: + Added a new functor template class, ACE_Malloc_Adapter_T, used + by ACE_Malloc_T as a factory of the ACE_LOCK template parameter, + and allows the use locking strategy classes that don't have a + satisfactory ctor taking a single required ACE_TCHAR* parameter, + which is the default. + + * ace/Process_Semaphore.{h,cpp}: + * ace/Thread_Semaphore.{h,cpp}: + Added template specializations of ACE_Malloc_Adapter_T for + ACE_Process_Semaphore and ACE_Thread_Semaphore since they don't + have a satisfactory ctor taking an ACT_TCHAR*. + Thu Dec 18 11:55:29 2003 Chad Elliott <elliott_c@ociweb.com> * ace/Null_Barrier.h: diff --git a/ace/Malloc_T.cpp b/ace/Malloc_T.cpp index 1812aa676f0..b46d34585b8 100644 --- a/ace/Malloc_T.cpp +++ b/ace/Malloc_T.cpp @@ -289,11 +289,9 @@ ACE_Malloc_T<ACE_MEM_POOL_2, ACE_LOCK, ACE_CB>::ACE_Malloc_T (const ACE_TCHAR *p bad_flag_ (0) { ACE_TRACE ("ACE_Malloc_T<ACE_MEM_POOL_2, ACE_LOCK, ACE_CB>::ACE_Malloc_T"); - if (pool_name == 0) - ACE_NEW (this->lock_, ACE_LOCK (pool_name)); // Want the ctor with char* - else - ACE_NEW (this->lock_, ACE_LOCK (ACE::basename (pool_name, - ACE_DIRECTORY_SEPARATOR_CHAR))); + if ((this->lock_ = ACE_Malloc_Lock_Adapter_T<ACE_LOCK> ()(pool_name)) == 0) + return; + this->delete_lock_ = 1; if ((this->bad_flag_ = this->open ()) == -1) @@ -310,11 +308,11 @@ ACE_Malloc_T<ACE_MEM_POOL_2, ACE_LOCK, ACE_CB>::ACE_Malloc_T (const ACE_TCHAR *p bad_flag_ (0) { ACE_TRACE ("ACE_Malloc_T<ACE_MEM_POOL_2, ACE_LOCK, ACE_CB>::ACE_Malloc_T"); - if (lock_name != 0) - ACE_NEW (this->lock_, ACE_LOCK (lock_name)); - else - ACE_NEW (this->lock_, ACE_LOCK (ACE::basename (pool_name, - ACE_DIRECTORY_SEPARATOR_CHAR))); + // Use pool_name for lock_name if lock_name not passed. + const ACE_TCHAR *name = lock_name ? lock_name : pool_name; + if ((this->lock_ = ACE_Malloc_Lock_Adapter_T<ACE_LOCK> ()(name)) == 0) + return; + this->delete_lock_ = 1; if ((this->bad_flag_ = this->open ()) == -1) @@ -359,7 +357,9 @@ ACE_Malloc_T<ACE_MEM_POOL_2, ACE_LOCK, ACE_CB>::ACE_Malloc_T (const ACE_TCHAR *p { ACE_TRACE ("ACE_Malloc_T<ACE_MEM_POOL_2, ACE_LOCK, ACE_CB>::ACE_Malloc_T"); - ACE_NEW (this->lock_, ACE_LOCK (lock_name)); + if ((this->lock_ = ACE_Malloc_Lock_Adapter_T<ACE_LOCK> ()(lock_name)) == 0) + return; + this->delete_lock_ = 1; if ((this->bad_flag_ = this->open ()) == -1) ACE_ERROR ((LM_ERROR, @@ -831,6 +831,23 @@ ACE_Malloc_T<ACE_MEM_POOL_2, ACE_LOCK, ACE_CB>::unbind (const char *name) return this->unbind (name, temp); } +/*****************************************************************************/ + +template <class ACE_LOCK> ACE_LOCK * +ACE_Malloc_Lock_Adapter_T<ACE_LOCK>::operator () (const ACE_TCHAR *name) +{ + ACE_LOCK *p = 0; + if (name == 0) + ACE_NEW_RETURN (p, ACE_LOCK (name), 0); + else + ACE_NEW_RETURN (p, ACE_LOCK (ACE::basename (name, + ACE_DIRECTORY_SEPARATOR_CHAR)), + 0); + return p; +} + +/*****************************************************************************/ + template <ACE_MEM_POOL_1, class ACE_LOCK, class ACE_CB> void ACE_Malloc_LIFO_Iterator_T<ACE_MEM_POOL_2, ACE_LOCK, ACE_CB>::dump (void) const { diff --git a/ace/Malloc_T.h b/ace/Malloc_T.h index 287a51b2898..da3f316ff46 100644 --- a/ace/Malloc_T.h +++ b/ace/Malloc_T.h @@ -650,6 +650,30 @@ private: int bad_flag_; }; +/*****************************************************************************/ + +/** + * @class ACE_Malloc_Lock_Adapter_T + * + * @brief Template functor adapter for lock strategies used with ACE_Malloc_T. + * + * This class acts as a factory for lock strategies that have various ctor + * signatures. If the lock strategy's ctor takes an ACE_TCHAR* as the first + * and only required parameter, it will just work. Otherwise use template + * specialization to create a version that matches the lock strategy's ctor + * signature. See ACE_Process_Semaphore and ACE_Thread_Semaphore for + * examples. + * + */ +template <class ACE_LOCK> +class ACE_Malloc_Lock_Adapter_T +{ +public: + ACE_LOCK * operator () (const ACE_TCHAR *name); +}; + +/*****************************************************************************/ + /** * @class ACE_Malloc_LIFO_Iterator_T * diff --git a/ace/Process_Semaphore.cpp b/ace/Process_Semaphore.cpp index 81a3fd1d07f..956f2afad0f 100644 --- a/ace/Process_Semaphore.cpp +++ b/ace/Process_Semaphore.cpp @@ -7,6 +7,8 @@ #include "ace/Process_Semaphore.inl" #endif /* __ACE_INLINE__ */ +#include "ace/ACE.h" + ACE_RCSID(ace, Process_Semaphore, "$Id$") void @@ -79,6 +81,21 @@ ACE_Process_Semaphore::release (void) return this->lock_.release (); } +/*****************************************************************************/ + +ACE_Process_Semaphore * +ACE_Malloc_Lock_Adapter_T<ACE_Process_Semaphore>::operator () (const ACE_TCHAR *name) +{ + ACE_Process_Semaphore *p = 0; + if (name == 0) + ACE_NEW_RETURN (p, ACE_Process_Semaphore (1, name), 0); + else + ACE_NEW_RETURN (p, ACE_Process_Semaphore (1, ACE::basename (name, + ACE_DIRECTORY_SEPARATOR_CHAR)), + 0); + return p; +} + // // These are instantiated both with and without ACE_HAS_THREADS. // diff --git a/ace/Process_Semaphore.h b/ace/Process_Semaphore.h index e68cb8daa2a..c9600d18490 100644 --- a/ace/Process_Semaphore.h +++ b/ace/Process_Semaphore.h @@ -134,6 +134,26 @@ protected: #endif /* ACE_WIN32 || ACE_HAS_POSIX_SEM || ACE_PSOS */ }; +/*****************************************************************************/ + +template <class T> class ACE_Malloc_Lock_Adapter_T; + +/** + * @class ACE_Malloc_Lock_Adapter_T<ACE_Process_Semaphore> + * + * @brief Template specialization of ACE_Malloc_Lock_Adapter_T for + * ACE_Process_Semaphore. + * + * This is needed since the ctor for ACE_Process_Semaphore doesn't match + * the standard form used by other lock strategy classes. + */ +ACE_TEMPLATE_SPECIALIZATION +class ACE_Export ACE_Malloc_Lock_Adapter_T<ACE_Process_Semaphore> +{ +public: + ACE_Process_Semaphore * operator () (const ACE_TCHAR *name); +}; + #if defined (__ACE_INLINE__) #include "ace/Process_Semaphore.inl" #endif /* __ACE_INLINE__ */ diff --git a/ace/Thread_Semaphore.cpp b/ace/Thread_Semaphore.cpp index e92b2838bc7..4e693f73028 100644 --- a/ace/Thread_Semaphore.cpp +++ b/ace/Thread_Semaphore.cpp @@ -17,6 +17,8 @@ #include "ace/Thread_Semaphore.inl" #endif /* __ACE_INLINE__ */ +#include "ace/ACE.h" + ACE_RCSID(ace, Thread_Semaphore, "$Id$") @@ -39,4 +41,19 @@ ACE_Thread_Semaphore::ACE_Thread_Semaphore (u_int count, // ACE_TRACE ("ACE_Thread_Semaphore::ACE_Thread_Semaphore"); } +/*****************************************************************************/ + +ACE_Thread_Semaphore * +ACE_Malloc_Lock_Adapter_T<ACE_Thread_Semaphore>::operator () (const ACE_TCHAR *name) +{ + ACE_Thread_Semaphore *p = 0; + if (name == 0) + ACE_NEW_RETURN (p, ACE_Thread_Semaphore (1, name), 0); + else + ACE_NEW_RETURN (p, ACE_Thread_Semaphore (1, ACE::basename (name, + ACE_DIRECTORY_SEPARATOR_CHAR)), + 0); + return p; +} + #endif /* ACE_HAS_THREADS */ diff --git a/ace/Thread_Semaphore.h b/ace/Thread_Semaphore.h index e39ec55ad14..0214b3e5941 100644 --- a/ace/Thread_Semaphore.h +++ b/ace/Thread_Semaphore.h @@ -55,6 +55,26 @@ public: ACE_ALLOC_HOOK_DECLARE; }; +/*****************************************************************************/ + +template <class T> class ACE_Malloc_Lock_Adapter_T; + +/** + * @class ACE_Malloc_Lock_Adapter_T<ACE_Thread_Semaphore> + * + * @brief Template specialization of ACE_Malloc_Lock_Adapter_T for + * ACE_Thread_Semaphore. + * + * This is needed since the ctor for ACE_Thread_Semaphore doesn't match + * the standard form used by other lock strategy classes. + */ +ACE_TEMPLATE_SPECIALIZATION +class ACE_Export ACE_Malloc_Lock_Adapter_T<ACE_Thread_Semaphore> +{ +public: + ACE_Thread_Semaphore * operator () (const ACE_TCHAR *name); +}; + #if defined (__ACE_INLINE__) #include "ace/Thread_Semaphore.inl" #endif /* __ACE_INLINE__ */ |