diff options
-rw-r--r-- | TAO/tao/Connect.cpp | 7 | ||||
-rw-r--r-- | TAO/tao/ORB.cpp | 3 | ||||
-rw-r--r-- | TAO/tao/ORB_Core.h | 7 | ||||
-rw-r--r-- | TAO/tao/ORB_Core.i | 10 | ||||
-rw-r--r-- | TAO/tao/POA.cpp | 8 | ||||
-rw-r--r-- | TAO/tao/POA.h | 3 | ||||
-rw-r--r-- | ace/OS.cpp | 181 | ||||
-rw-r--r-- | ace/OS.i | 146 | ||||
-rw-r--r-- | ace/Strategies.h | 13 | ||||
-rw-r--r-- | ace/Strategies.i | 16 | ||||
-rw-r--r-- | ace/Strategies_T.cpp | 16 | ||||
-rw-r--r-- | ace/Strategies_T.h | 21 | ||||
-rw-r--r-- | ace/Strategies_T.i | 13 | ||||
-rw-r--r-- | tests/Conn_Test.cpp | 11 |
14 files changed, 266 insertions, 189 deletions
diff --git a/TAO/tao/Connect.cpp b/TAO/tao/Connect.cpp index e5ab5f7020c..18e3a7da78a 100644 --- a/TAO/tao/Connect.cpp +++ b/TAO/tao/Connect.cpp @@ -238,6 +238,7 @@ TAO_Server_Connection_Handler::handle_message (TAO_InputCDR &input, this->orb_core_->root_poa ()->dispatch_servant (request.object_key (), request, 0, + this->orb_core_, env); @@ -291,6 +292,7 @@ TAO_Server_Connection_Handler::handle_locate (TAO_InputCDR &input, the_poa->dispatch_servant (serverRequest.object_key (), serverRequest, 0, + this->orb_core_, env); @@ -1116,12 +1118,10 @@ TAO_Client_Connection_Handler::close (u_long flags) #define TAO_SVC_TUPLE ACE_Svc_Tuple<TAO_Client_Connection_Handler> #define CACHED_CONNECT_STRATEGY ACE_Cached_Connect_Strategy<TAO_Client_Connection_Handler, TAO_SOCK_CONNECTOR, TAO_Cached_Connector_Lock> -#define HASH_ADDR ACE_Hash_Addr<ACE_INET_Addr> -#define REFCOUNTED_HASH_RECYCLABLE_ADDR ACE_Refcounted_Hash_Recyclable<ACE_Hash_Addr<ACE_INET_Addr> > +#define REFCOUNTED_HASH_RECYCLABLE_ADDR ACE_Refcounted_Hash_Recyclable<ACE_INET_Addr> #if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) template class ACE_Svc_Handler<TAO_SOCK_STREAM, ACE_NULL_SYNCH>; -template class HASH_ADDR; template class REFCOUNTED_HASH_RECYCLABLE_ADDR; template class TAO_SVC_TUPLE; template class ACE_Map_Manager<int, TAO_SVC_TUPLE*, ACE_SYNCH_RW_MUTEX>; @@ -1131,7 +1131,6 @@ template class ACE_Map_Reverse_Iterator<int, TAO_SVC_TUPLE*, ACE_SYNCH_RW_MUTEX> template class ACE_Map_Entry<int, TAO_SVC_TUPLE*>; #elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) #pragma instantiate ACE_Svc_Handler<TAO_SOCK_STREAM, ACE_NULL_SYNCH> -#pragma instantiate HASH_ADDR #pragma instantiate REFCOUNTED_HASH_RECYCLABLE_ADDR #pragma instantiate TAO_SVC_TUPLE #pragma instantiate ACE_Map_Manager<int, TAO_SVC_TUPLE*, ACE_SYNCH_RW_MUTEX> diff --git a/TAO/tao/ORB.cpp b/TAO/tao/ORB.cpp index 6e69f56f1a5..bdc2e5d419f 100644 --- a/TAO/tao/ORB.cpp +++ b/TAO/tao/ORB.cpp @@ -872,8 +872,7 @@ operator>>(TAO_InputCDR& cdr, TAO_opaque& x) // **************************************************************** #define CACHED_CONNECT_STRATEGY ACE_Cached_Connect_Strategy<TAO_Client_Connection_Handler, TAO_SOCK_CONNECTOR, TAO_Cached_Connector_Lock> -#define HASH_ADDR ACE_Hash_Addr<ACE_INET_Addr> -#define REFCOUNTED_HASH_RECYCLABLE_ADDR ACE_Refcounted_Hash_Recyclable<ACE_Hash_Addr<ACE_INET_Addr> > +#define REFCOUNTED_HASH_RECYCLABLE_ADDR ACE_Refcounted_Hash_Recyclable<ACE_INET_Addr> #if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) diff --git a/TAO/tao/ORB_Core.h b/TAO/tao/ORB_Core.h index 79748768c36..42a907def76 100644 --- a/TAO/tao/ORB_Core.h +++ b/TAO/tao/ORB_Core.h @@ -664,8 +664,13 @@ extern TAO_Export TAO_ORB_Core *TAO_ORB_Core_instance (void); #if defined (ACE_WIN32) #pragma warning(disable:4231) -extern template size_t + +extern template u_long +ACE_Refcounted_Hash_Recyclable<ACE_INET_Addr>::hash_i (void) const; + +extern template u_long ACE_Hash_Addr<ACE_INET_Addr>::hash_i (const ACE_INET_Addr &addr) const; + #endif /* ACE_WIN32 */ #endif /* TAO_ORB_CORE_H */ diff --git a/TAO/tao/ORB_Core.i b/TAO/tao/ORB_Core.i index f3df9a4d8e5..b85d0e2fac9 100644 --- a/TAO/tao/ORB_Core.i +++ b/TAO/tao/ORB_Core.i @@ -139,11 +139,19 @@ TAO_ORB_Core::using_collocation (CORBA::Boolean use_col) #if defined (ACE_HAS_TEMPLATE_SPECIALIZATION) && (!defined (__GNUG__) || (__GNUC__ > 2 || __GNUC_MINOR__ >= 90)) # if defined (__ACE_INLINE__) || (!defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) && !defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)) -ACE_INLINE size_t + +ACE_INLINE u_long +ACE_Refcounted_Hash_Recyclable<ACE_INET_Addr>::hash_i (void) const +{ + return this->t_.get_ip_address () + this->t_.get_port_number (); +} + +ACE_INLINE u_long ACE_Hash_Addr<ACE_INET_Addr>::hash_i (const ACE_INET_Addr &addr) const { return addr.get_ip_address () + addr.get_port_number (); } + # endif /* __ACE_INLINE__ */ #endif /* ACE_HAS_TEMPLATE_SPECIALIZATION && egcs, if __GNUG__ */ diff --git a/TAO/tao/POA.cpp b/TAO/tao/POA.cpp index f86f9fe5907..1627643243e 100644 --- a/TAO/tao/POA.cpp +++ b/TAO/tao/POA.cpp @@ -2137,6 +2137,7 @@ TAO_POA::locate_poa_and_servant_i (const TAO_ObjectKey &key, const char *operation, PortableServer::ObjectId &id, TAO_POA *&poa_impl, + TAO_ORB_Core *orb_core, CORBA::Environment &env) { ACE_FUNCTION_TIMEPROBE (TAO_POA_LOCATE_POA_AND_SERVANT_I_START); @@ -2292,7 +2293,6 @@ TAO_POA::locate_poa_and_servant_i (const TAO_ObjectKey &key, return 0; // Remember the cookie - TAO_ORB_Core *orb_core = TAO_ORB_Core_instance (); TAO_POA_Current *poa_current = orb_core->poa_current (); poa_current->locator_cookie (cookie); @@ -2311,6 +2311,7 @@ void TAO_POA::dispatch_servant (const TAO_ObjectKey &key, CORBA::ServerRequest &req, void *context, + TAO_ORB_Core *orb_core, CORBA::Environment &env) { ACE_FUNCTION_TIMEPROBE (TAO_POA_DISPATCH_SERVANT_START); @@ -2318,13 +2319,14 @@ TAO_POA::dispatch_servant (const TAO_ObjectKey &key, // Lock access to the POAManager for the duration of this transaction TAO_POA_READ_GUARD (ACE_Lock, monitor, this->lock (), env); - this->dispatch_servant_i (key, req, context, env); + this->dispatch_servant_i (key, req, context, orb_core, env); } void TAO_POA::dispatch_servant_i (const TAO_ObjectKey &key, CORBA::ServerRequest &req, void *context, + TAO_ORB_Core *orb_core, CORBA::Environment &env) { PortableServer::ObjectId id; @@ -2332,7 +2334,6 @@ TAO_POA::dispatch_servant_i (const TAO_ObjectKey &key, const char *operation = req.operation (); // Setup for POA Current - TAO_ORB_Core *orb_core = TAO_ORB_Core_instance (); TAO_POA_Current current_context; // Set the current context and remember the old one TAO_POA_Current *previous_context = orb_core->poa_current (¤t_context); @@ -2341,6 +2342,7 @@ TAO_POA::dispatch_servant_i (const TAO_ObjectKey &key, operation, id, poa, + orb_core, env); if (env.exception () != 0 || servant == 0) return; diff --git a/TAO/tao/POA.h b/TAO/tao/POA.h index b4da10e4d00..e9be1717a16 100644 --- a/TAO/tao/POA.h +++ b/TAO/tao/POA.h @@ -530,6 +530,7 @@ public: virtual void dispatch_servant (const TAO_ObjectKey &key, CORBA::ServerRequest &req, void *context, + TAO_ORB_Core *orb_core, CORBA_Environment &_env = CORBA_Environment::default_environment ()); virtual int locate_servant (const TAO_ObjectKey &key, @@ -673,6 +674,7 @@ protected: const char *operation, PortableServer::ObjectId &id, TAO_POA *&poa_impl, + TAO_ORB_Core *orb_core, CORBA_Environment &_env = CORBA_Environment::default_environment ()); virtual TAO_POA *locate_poa_i (const TAO_ObjectKey &key, @@ -682,6 +684,7 @@ protected: virtual void dispatch_servant_i (const TAO_ObjectKey &key, CORBA::ServerRequest &req, void *context, + TAO_ORB_Core *orb_core, CORBA_Environment &_env = CORBA_Environment::default_environment ()); virtual void pre_invoke (const TAO_ObjectKey &key, diff --git a/ace/OS.cpp b/ace/OS.cpp index 7e2a83a7006..65716f9310f 100644 --- a/ace/OS.cpp +++ b/ace/OS.cpp @@ -4127,6 +4127,187 @@ ACE_OS::pwrite (ACE_HANDLE handle, # endif /* ACE_HAD_P_READ_WRITE */ } +ACE_HANDLE +ACE_OS::open (const char *filename, + int mode, + int perms, + LPSECURITY_ATTRIBUTES sa) +{ + // ACE_TRACE ("ACE_OS::open"); +#if defined (ACE_HAS_WINCE) + ACE_UNUSED_ARG (filename); + ACE_UNUSED_ARG (mode); + ACE_UNUSED_ARG (perms); + ACE_UNUSED_ARG (sa); + return 0; +#elif defined (ACE_WIN32) + ACE_UNUSED_ARG (perms); + + DWORD access = GENERIC_READ; + if (ACE_BIT_ENABLED (mode, O_WRONLY)) + access = GENERIC_WRITE; + else if (ACE_BIT_ENABLED (mode, O_RDWR)) + access = GENERIC_READ | GENERIC_WRITE; + + DWORD creation = OPEN_EXISTING; + + if ((mode & (_O_CREAT | _O_EXCL)) == (_O_CREAT | _O_EXCL)) + creation = CREATE_NEW; + else if ((mode & (_O_CREAT | _O_TRUNC)) == (_O_CREAT | _O_TRUNC)) + creation = CREATE_ALWAYS; + else if (ACE_BIT_ENABLED (mode, _O_CREAT)) + creation = OPEN_ALWAYS; + else if (ACE_BIT_ENABLED (mode, _O_TRUNC)) + creation = TRUNCATE_EXISTING; + + DWORD flags = 0; + + if (ACE_BIT_ENABLED (mode, _O_TEMPORARY)) + flags |= FILE_FLAG_DELETE_ON_CLOSE; + + if (ACE_BIT_ENABLED (mode, FILE_FLAG_WRITE_THROUGH)) + flags |= FILE_FLAG_WRITE_THROUGH; + if (ACE_BIT_ENABLED (mode, FILE_FLAG_OVERLAPPED)) + flags |= FILE_FLAG_OVERLAPPED; + if (ACE_BIT_ENABLED (mode, FILE_FLAG_NO_BUFFERING)) + flags |= FILE_FLAG_NO_BUFFERING; + if (ACE_BIT_ENABLED (mode, FILE_FLAG_RANDOM_ACCESS)) + flags |= FILE_FLAG_RANDOM_ACCESS; + if (ACE_BIT_ENABLED (mode, FILE_FLAG_SEQUENTIAL_SCAN)) + flags |= FILE_FLAG_SEQUENTIAL_SCAN; + if (ACE_BIT_ENABLED (mode, FILE_FLAG_DELETE_ON_CLOSE)) + flags |= FILE_FLAG_DELETE_ON_CLOSE; + if (ACE_BIT_ENABLED (mode, FILE_FLAG_BACKUP_SEMANTICS)) + flags |= FILE_FLAG_BACKUP_SEMANTICS; + if (ACE_BIT_ENABLED (mode, FILE_FLAG_POSIX_SEMANTICS)) + flags |= FILE_FLAG_POSIX_SEMANTICS; + + ACE_MT (ACE_Thread_Mutex *ace_os_monitor_lock = 0;) + + if (ACE_BIT_ENABLED (mode, _O_APPEND)) + { + ACE_MT + ( + ace_os_monitor_lock = + ACE_Managed_Object<ACE_Thread_Mutex>::get_preallocated_object (ACE_Object_Manager::ACE_OS_MONITOR_LOCK); + ace_os_monitor_lock->acquire (); + ) + } + + ACE_HANDLE h = ::CreateFileA (filename, access, + FILE_SHARE_READ | FILE_SHARE_WRITE, + ACE_OS::default_win32_security_attributes (sa), + creation, + flags, + 0); + + if (ACE_BIT_ENABLED (mode, _O_APPEND)) + { + if (h != ACE_INVALID_HANDLE) + { + ::SetFilePointer (h, 0, 0, FILE_END); + } + + ACE_MT (ace_os_monitor_lock->release ();) + } + + if (h == ACE_INVALID_HANDLE) + ACE_FAIL_RETURN (h); + else + return h; +#else + ACE_UNUSED_ARG (sa); + ACE_OSCALL_RETURN (::open (filename, mode, perms), ACE_HANDLE, -1); +#endif /* ACE_WIN32 */ +} + +#if defined (ACE_HAS_UNICODE) && defined (ACE_WIN32) + +ACE_HANDLE +ACE_OS::open (const wchar_t *filename, + int mode, + int perms, + LPSECURITY_ATTRIBUTES sa) +{ + ACE_UNUSED_ARG (perms); + // ACE_TRACE ("ACE_OS::open"); + // Warning: This function ignores _O_APPEND + DWORD access = GENERIC_READ; + if (ACE_BIT_ENABLED (mode, O_WRONLY)) + access = GENERIC_WRITE; + else if (ACE_BIT_ENABLED (mode, O_RDWR)) + access = GENERIC_READ | GENERIC_WRITE; + + DWORD creation = OPEN_EXISTING; + + if ((mode & (_O_CREAT | _O_EXCL)) == (_O_CREAT | _O_EXCL)) + creation = CREATE_NEW; + else if ((mode & (_O_CREAT | _O_TRUNC)) == (_O_CREAT | _O_TRUNC)) + creation = CREATE_ALWAYS; + else if (ACE_BIT_ENABLED (mode, _O_CREAT)) + creation = OPEN_ALWAYS; + else if (ACE_BIT_ENABLED (mode, _O_TRUNC)) + creation = TRUNCATE_EXISTING; + + DWORD flags = 0; + + if (ACE_BIT_ENABLED (mode, _O_TEMPORARY)) + flags |= FILE_FLAG_DELETE_ON_CLOSE; + + if (ACE_BIT_ENABLED (mode, FILE_FLAG_WRITE_THROUGH)) + flags |= FILE_FLAG_WRITE_THROUGH; + if (ACE_BIT_ENABLED (mode, FILE_FLAG_OVERLAPPED)) + flags |= FILE_FLAG_OVERLAPPED; + if (ACE_BIT_ENABLED (mode, FILE_FLAG_NO_BUFFERING)) + flags |= FILE_FLAG_NO_BUFFERING; + if (ACE_BIT_ENABLED (mode, FILE_FLAG_RANDOM_ACCESS)) + flags |= FILE_FLAG_RANDOM_ACCESS; + if (ACE_BIT_ENABLED (mode, FILE_FLAG_SEQUENTIAL_SCAN)) + flags |= FILE_FLAG_SEQUENTIAL_SCAN; + if (ACE_BIT_ENABLED (mode, FILE_FLAG_DELETE_ON_CLOSE)) + flags |= FILE_FLAG_DELETE_ON_CLOSE; + if (ACE_BIT_ENABLED (mode, FILE_FLAG_BACKUP_SEMANTICS)) + flags |= FILE_FLAG_BACKUP_SEMANTICS; + if (ACE_BIT_ENABLED (mode, FILE_FLAG_POSIX_SEMANTICS)) + flags |= FILE_FLAG_POSIX_SEMANTICS; + + ACE_MT (ACE_Thread_Mutex *ace_os_monitor_lock = 0;) + + if (ACE_BIT_ENABLED (mode, _O_APPEND)) + { + ACE_MT + ( + ace_os_monitor_lock = + ACE_Managed_Object<ACE_Thread_Mutex>::get_preallocated_object (ACE_Object_Manager::ACE_OS_MONITOR_LOCK); + ace_os_monitor_lock->acquire (); + ) + } + + ACE_HANDLE h = ::CreateFileW (filename, access, + FILE_SHARE_READ | FILE_SHARE_WRITE, + ACE_OS::default_win32_security_attributes (sa), + creation, + flags, + 0); + + if (ACE_BIT_ENABLED (mode, _O_APPEND)) + { + if (h != ACE_INVALID_HANDLE) + { + ::SetFilePointer (h, 0, 0, FILE_END); + } + + ACE_MT (ace_os_monitor_lock->release ();) + } + + if (h == ACE_INVALID_HANDLE) + ACE_FAIL_RETURN (h); + else + return h; +} + +#endif /* ACE_HAS_UNICODE && ACE_WIN32 */ + # if defined (ACE_LACKS_DIFFTIME) double ACE_OS::difftime (time_t t1, time_t t0) @@ -7786,88 +7786,6 @@ ACE_OS::shmget (key_t key, int size, int flags) #endif /* ACE_HAS_SYSV_IPC */ } -ACE_INLINE ACE_HANDLE -ACE_OS::open (const char *filename, - int mode, - int perms, - LPSECURITY_ATTRIBUTES sa) -{ - // ACE_TRACE ("ACE_OS::open"); -#if defined (ACE_HAS_WINCE) - ACE_UNUSED_ARG (filename); - ACE_UNUSED_ARG (mode); - ACE_UNUSED_ARG (perms); - ACE_UNUSED_ARG (sa); - return 0; -#elif defined (ACE_WIN32) - ACE_UNUSED_ARG (perms); - ACE_MT (ACE_Thread_Mutex *ace_os_monitor_lock = 0); - - DWORD access = GENERIC_READ; - if (ACE_BIT_ENABLED (mode, O_WRONLY)) - access = GENERIC_WRITE; - else if (ACE_BIT_ENABLED (mode, O_RDWR)) - access = GENERIC_READ | GENERIC_WRITE; - - DWORD creation = OPEN_EXISTING; - - if ((mode & (_O_CREAT | _O_EXCL)) == (_O_CREAT | _O_EXCL)) - creation = CREATE_NEW; - else if ((mode & (_O_CREAT | _O_TRUNC)) == (_O_CREAT | _O_TRUNC)) - creation = CREATE_ALWAYS; - else if (ACE_BIT_ENABLED (mode, _O_CREAT)) - creation = OPEN_ALWAYS; - else if (ACE_BIT_ENABLED (mode, _O_TRUNC)) - creation = TRUNCATE_EXISTING; - - DWORD flags = 0; - - if (ACE_BIT_ENABLED (mode, _O_TEMPORARY)) - flags |= FILE_FLAG_DELETE_ON_CLOSE; - - if (ACE_BIT_ENABLED (mode, FILE_FLAG_WRITE_THROUGH)) - flags |= FILE_FLAG_WRITE_THROUGH; - if (ACE_BIT_ENABLED (mode, FILE_FLAG_OVERLAPPED)) - flags |= FILE_FLAG_OVERLAPPED; - if (ACE_BIT_ENABLED (mode, FILE_FLAG_NO_BUFFERING)) - flags |= FILE_FLAG_NO_BUFFERING; - if (ACE_BIT_ENABLED (mode, FILE_FLAG_RANDOM_ACCESS)) - flags |= FILE_FLAG_RANDOM_ACCESS; - if (ACE_BIT_ENABLED (mode, FILE_FLAG_SEQUENTIAL_SCAN)) - flags |= FILE_FLAG_SEQUENTIAL_SCAN; - if (ACE_BIT_ENABLED (mode, FILE_FLAG_DELETE_ON_CLOSE)) - flags |= FILE_FLAG_DELETE_ON_CLOSE; - if (ACE_BIT_ENABLED (mode, FILE_FLAG_BACKUP_SEMANTICS)) - flags |= FILE_FLAG_BACKUP_SEMANTICS; - if (ACE_BIT_ENABLED (mode, FILE_FLAG_POSIX_SEMANTICS)) - flags |= FILE_FLAG_POSIX_SEMANTICS; - - ACE_MT (if (ACE_BIT_ENABLED (mode, _O_APPEND)) { ace_os_monitor_lock = - ACE_Managed_Object<ACE_Thread_Mutex>::get_preallocated_object - (ACE_Object_Manager::ACE_OS_MONITOR_LOCK); - ace_os_monitor_lock->acquire (); }) - - ACE_HANDLE h = ::CreateFileA (filename, access, - FILE_SHARE_READ | FILE_SHARE_WRITE, - ACE_OS::default_win32_security_attributes (sa), - creation, - flags, - 0); - - if (h == ACE_INVALID_HANDLE) - ACE_FAIL_RETURN (h); - - ACE_MT (if (ace_os_monitor_lock != 0)) - ::SetFilePointer (h, 0, 0, FILE_END); - ACE_MT (ace_os_monitor_lock->release ()); - - return h; -#else - ACE_UNUSED_ARG (sa); - ACE_OSCALL_RETURN (::open (filename, mode, perms), ACE_HANDLE, -1); -#endif /* ACE_WIN32 */ -} - #if !defined (ACE_HAS_MOSTLY_UNICODE_APIS) ACE_INLINE ACE_HANDLE ACE_OS::shm_open (const char *filename, @@ -9613,70 +9531,6 @@ ACE_OS::hostname (wchar_t *name, size_t maxnamelen) # endif /* ! ACE_HAS_WINCE */ } -ACE_INLINE ACE_HANDLE -ACE_OS::open (const wchar_t *filename, - int mode, - int perms, - LPSECURITY_ATTRIBUTES sa) -{ - ACE_UNUSED_ARG (perms); - // ACE_TRACE ("ACE_OS::open"); - // Warning: This function ignores _O_APPEND - DWORD access = GENERIC_READ; - if (ACE_BIT_ENABLED (mode, O_WRONLY)) - access = GENERIC_WRITE; - else if (ACE_BIT_ENABLED (mode, O_RDWR)) - access = GENERIC_READ | GENERIC_WRITE; - - DWORD creation = OPEN_EXISTING; - - if ((mode & (_O_CREAT | _O_EXCL)) == (_O_CREAT | _O_EXCL)) - creation = CREATE_NEW; - else if ((mode & (_O_CREAT | _O_TRUNC)) == (_O_CREAT | _O_TRUNC)) - creation = CREATE_ALWAYS; - else if (ACE_BIT_ENABLED (mode, _O_CREAT)) - creation = OPEN_ALWAYS; - else if (ACE_BIT_ENABLED (mode, _O_TRUNC)) - creation = TRUNCATE_EXISTING; - - DWORD flags = 0; - - if (ACE_BIT_ENABLED (mode, _O_TEMPORARY)) - flags |= FILE_FLAG_DELETE_ON_CLOSE; - - if (ACE_BIT_ENABLED (mode, FILE_FLAG_WRITE_THROUGH)) - flags |= FILE_FLAG_WRITE_THROUGH; - if (ACE_BIT_ENABLED (mode, FILE_FLAG_OVERLAPPED)) - flags |= FILE_FLAG_OVERLAPPED; - if (ACE_BIT_ENABLED (mode, FILE_FLAG_NO_BUFFERING)) - flags |= FILE_FLAG_NO_BUFFERING; - if (ACE_BIT_ENABLED (mode, FILE_FLAG_RANDOM_ACCESS)) - flags |= FILE_FLAG_RANDOM_ACCESS; - if (ACE_BIT_ENABLED (mode, FILE_FLAG_SEQUENTIAL_SCAN)) - flags |= FILE_FLAG_SEQUENTIAL_SCAN; - if (ACE_BIT_ENABLED (mode, FILE_FLAG_DELETE_ON_CLOSE)) - flags |= FILE_FLAG_DELETE_ON_CLOSE; - if (ACE_BIT_ENABLED (mode, FILE_FLAG_BACKUP_SEMANTICS)) - flags |= FILE_FLAG_BACKUP_SEMANTICS; - if (ACE_BIT_ENABLED (mode, FILE_FLAG_POSIX_SEMANTICS)) - flags |= FILE_FLAG_POSIX_SEMANTICS; - - ACE_HANDLE h = ::CreateFileW (filename, access, - FILE_SHARE_READ | FILE_SHARE_WRITE, - ACE_OS::default_win32_security_attributes (sa), - creation, - flags, - 0); - - if (h == ACE_INVALID_HANDLE) - ACE_FAIL_RETURN (h); - - if (ACE_BIT_ENABLED (mode, _O_APPEND)) - ::SetFilePointer (h, 0, 0, FILE_END); - - return h; -} - ACE_INLINE int ACE_OS::unlink (const wchar_t *path) { diff --git a/ace/Strategies.h b/ace/Strategies.h index 03bd8d2d71d..eba011d1d26 100644 --- a/ace/Strategies.h +++ b/ace/Strategies.h @@ -139,12 +139,21 @@ public: virtual ~ACE_Hashable (void); // Destructor. - virtual u_long hash (void) const = 0; - // Computes and returns hash value. + virtual u_long hash (void) const; + // Computes and returns hash value. This "caches" the hash value to + // improve performance. protected: ACE_Hashable (void); // Protected constructor. + + virtual u_long hash_i (void) const = 0; + // This is the method that actually performs the non-cached hash + // computation. + + u_long hash_value_; + // Pre-computed hash-value. + }; class ACE_Export ACE_Refcountable diff --git a/ace/Strategies.i b/ace/Strategies.i index a0ef94ea2da..2d101275030 100644 --- a/ace/Strategies.i +++ b/ace/Strategies.i @@ -38,6 +38,7 @@ ACE_Recyclable::state (ACE_Recyclable::State new_state) ACE_INLINE ACE_Hashable::ACE_Hashable (void) + : hash_value_ (0) { } @@ -46,6 +47,21 @@ ACE_Hashable::~ACE_Hashable (void) { } +ACE_INLINE u_long +ACE_Hashable::hash (void) const +{ + // In doing the check below, we take chance of paying a performance + // price when the hash value is zero. But, that will (hopefully) + // happen far less often than a non-zero value, so this caching + // strategy should pay off, esp. if hash computation is expensive + // relative to the simple comparison. + + if (this->hash_value_ == 0) + ((ACE_Hashable *) this)->hash_value_ = this->hash_i (); + + return this->hash_value_; +} + ACE_INLINE ACE_Refcountable::ACE_Refcountable (int refcount) : refcount_ (refcount) diff --git a/ace/Strategies_T.cpp b/ace/Strategies_T.cpp index 03550ae301a..2fe6d226390 100644 --- a/ace/Strategies_T.cpp +++ b/ace/Strategies_T.cpp @@ -468,8 +468,7 @@ ACE_Cached_Connect_Strategy<SVC_HANDLER, ACE_PEER_CONNECTOR_2, MUTEX>::check_hin int reuse_addr, int flags, int perms, - ACE_Hash_Addr<ACE_PEER_CONNECTOR_ADDR> &search_addr, - ACE_Hash_Map_Entry<ACE_Refcounted_Hash_Recyclable<ACE_Hash_Addr<ACE_PEER_CONNECTOR_ADDR> >, SVC_HANDLER *> *&entry, + ACE_Hash_Map_Entry<ACE_Refcounted_Hash_Recyclable<ACE_PEER_CONNECTOR_ADDR>, SVC_HANDLER *> *&entry, int &found) { ACE_UNUSED_ARG (remote_addr); @@ -503,7 +502,7 @@ ACE_Cached_Connect_Strategy<SVC_HANDLER, ACE_PEER_CONNECTOR_2, MUTEX>::check_hin // If hint is not closed, see if it is connected to the correct // address and is recyclable - else if (possible_entry->ext_id_ == search_addr) + else if (possible_entry->ext_id_ == remote_addr) { // Hint successful found = 1; @@ -540,10 +539,12 @@ ACE_Cached_Connect_Strategy<SVC_HANDLER, ACE_PEER_CONNECTOR_2, MUTEX>::find_or_c int reuse_addr, int flags, int perms, - ACE_Hash_Addr<ACE_PEER_CONNECTOR_ADDR> &search_addr, - ACE_Hash_Map_Entry<ACE_Refcounted_Hash_Recyclable<ACE_Hash_Addr<ACE_PEER_CONNECTOR_ADDR> >, SVC_HANDLER *> *&entry, + ACE_Hash_Map_Entry<ACE_Refcounted_Hash_Recyclable<ACE_PEER_CONNECTOR_ADDR>, SVC_HANDLER *> *&entry, int &found) { + // Explicit type conversion + REFCOUNTED_HASH_RECYCLABLE_ADDRESS search_addr (remote_addr); + // Try to find the address in the cache. Only if we don't find it // do we create a new <SVC_HANDLER> and connect it with the server. if (this->connection_cache_.find (search_addr, entry) == -1) @@ -621,9 +622,6 @@ ACE_Cached_Connect_Strategy<SVC_HANDLER, ACE_PEER_CONNECTOR_2, MUTEX>::connect_s { CONNECTION_MAP_ENTRY *entry = 0; - // Create the search key - HASH_ADDRESS search_addr (remote_addr); - // Synchronization is required here as the setting of the // recyclable state must be done atomically with the finding and // binding of the service handler in the cache. @@ -639,7 +637,6 @@ ACE_Cached_Connect_Strategy<SVC_HANDLER, ACE_PEER_CONNECTOR_2, MUTEX>::connect_s reuse_addr, flags, perms, - search_addr, entry, found); if (result != 0) @@ -656,7 +653,6 @@ ACE_Cached_Connect_Strategy<SVC_HANDLER, ACE_PEER_CONNECTOR_2, MUTEX>::connect_s reuse_addr, flags, perms, - search_addr, entry, found); if (result != 0) diff --git a/ace/Strategies_T.h b/ace/Strategies_T.h index 6affd6c6dbe..a23cd067bc0 100644 --- a/ace/Strategies_T.h +++ b/ace/Strategies_T.h @@ -716,7 +716,7 @@ public: // Compares two hash values. private: - size_t hash_i (const ADDR_T &) const; + u_long hash_i (const ADDR_T &) const; // This is the method that actually performs the non-cached hash // computation. It should typically be specialized. @@ -744,13 +744,16 @@ public: virtual ~ACE_Refcounted_Hash_Recyclable (void); // Destructor - u_long hash (void) const; - // Computes and returns hash value. - int operator== (const ACE_Refcounted_Hash_Recyclable<T> &rhs) const; // Compares two instances. + int operator== (const T &rhs) const; + // Compares two instances. + protected: + u_long hash_i (void) const; + // Computes and returns hash value. + T t_; }; @@ -861,9 +864,7 @@ public: CONNECT_STRATEGY; // = Typedefs for managing the map - typedef ACE_Hash_Addr<ACE_PEER_CONNECTOR_ADDR> - HASH_ADDRESS; - typedef ACE_Refcounted_Hash_Recyclable<HASH_ADDRESS> + typedef ACE_Refcounted_Hash_Recyclable<ACE_PEER_CONNECTOR_ADDR> REFCOUNTED_HASH_RECYCLABLE_ADDRESS; typedef ACE_Hash_Map_Manager <REFCOUNTED_HASH_RECYCLABLE_ADDRESS, SVC_HANDLER *, ACE_Null_Mutex> CONNECTION_MAP; @@ -899,8 +900,7 @@ protected: int reuse_addr, int flags, int perms, - ACE_Hash_Addr<ACE_PEER_CONNECTOR_ADDR> &search_addr, - ACE_Hash_Map_Entry<ACE_Refcounted_Hash_Recyclable<ACE_Hash_Addr<ACE_PEER_CONNECTOR_ADDR> >, SVC_HANDLER *> *&entry, + ACE_Hash_Map_Entry<ACE_Refcounted_Hash_Recyclable<ACE_PEER_CONNECTOR_ADDR>, SVC_HANDLER *> *&entry, int &found); int find_or_create_svc_handler_i (SVC_HANDLER *&sh, @@ -910,8 +910,7 @@ protected: int reuse_addr, int flags, int perms, - ACE_Hash_Addr<ACE_PEER_CONNECTOR_ADDR> &search_addr, - ACE_Hash_Map_Entry<ACE_Refcounted_Hash_Recyclable<ACE_Hash_Addr<ACE_PEER_CONNECTOR_ADDR> >, SVC_HANDLER *> *&entry, + ACE_Hash_Map_Entry<ACE_Refcounted_Hash_Recyclable<ACE_PEER_CONNECTOR_ADDR>, SVC_HANDLER *> *&entry, int &found); CONNECTION_MAP connection_cache_; diff --git a/ace/Strategies_T.i b/ace/Strategies_T.i index cdd1188ec5b..86a5671a34b 100644 --- a/ace/Strategies_T.i +++ b/ace/Strategies_T.i @@ -393,7 +393,7 @@ ACE_Refcounted_Hash_Recyclable<T>::~ACE_Refcounted_Hash_Recyclable (void) } template <class T> ASYS_INLINE u_long -ACE_Refcounted_Hash_Recyclable<T>::hash (void) const +ACE_Refcounted_Hash_Recyclable<T>::hash_i (void) const { return this->t_.hash (); } @@ -407,6 +407,15 @@ ACE_Refcounted_Hash_Recyclable<T>::operator== (const ACE_Refcounted_Hash_Recycla return this->t_ == rhs.t_; } +template <class T> ASYS_INLINE int +ACE_Refcounted_Hash_Recyclable<T>::operator== (const T &rhs) const +{ + if (this->state () != ACE_Recyclable::IDLE) + return 0; + else + return this->t_ == rhs; +} + template<class ADDR_T> ASYS_INLINE ACE_Hash_Addr<ADDR_T>::ACE_Hash_Addr (void) : hash_value_ (0) @@ -436,7 +445,7 @@ ACE_Hash_Addr<ADDR_T>::hash (void) const return this->hash_value_; } -template<class ADDR_T> ASYS_INLINE size_t +template<class ADDR_T> ASYS_INLINE u_long ACE_Hash_Addr<ADDR_T>::hash_i (const ADDR_T &b) const { ACE_UNUSED_ARG (b); diff --git a/tests/Conn_Test.cpp b/tests/Conn_Test.cpp index 8e5000e5037..a6471fa4e20 100644 --- a/tests/Conn_Test.cpp +++ b/tests/Conn_Test.cpp @@ -181,10 +181,10 @@ Svc_Handler::idle (u_long flags) // can't deal with them, though. #if defined (ACE_HAS_TEMPLATE_SPECIALIZATION) && !defined (ACE_HAS_GNUG_PRE_2_8) -size_t -ACE_Hash_Addr<ACE_INET_Addr>::hash_i (const ACE_INET_Addr &addr) const +u_long +ACE_Refcounted_Hash_Recyclable<ACE_INET_Addr>::hash_i (void) const { - return addr.get_ip_address () + addr.get_port_number (); + return this->t_.get_ip_address () + this->t_.get_port_number (); } #endif /* ACE_HAS_TEMPLATE_SPECIALIZATION && newer g++, if __GNUG__ */ @@ -698,12 +698,10 @@ main (int argc, ASYS_TCHAR *argv[]) } #define CACHED_CONNECT_STRATEGY ACE_Cached_Connect_Strategy<Svc_Handler, ACE_SOCK_CONNECTOR, ACE_SYNCH_MUTEX> -#define HASH_ADDR ACE_Hash_Addr<ACE_INET_Addr> -#define REFCOUNTED_HASH_RECYCLABLE_ADDR ACE_Refcounted_Hash_Recyclable<ACE_Hash_Addr<ACE_INET_Addr> > +#define REFCOUNTED_HASH_RECYCLABLE_ADDR ACE_Refcounted_Hash_Recyclable<ACE_INET_Addr> #if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) template class CACHED_CONNECT_STRATEGY; -template class HASH_ADDR; template class REFCOUNTED_HASH_RECYCLABLE_ADDR; template class ACE_NOOP_Creation_Strategy<Svc_Handler>; template class ACE_Concurrency_Strategy<Svc_Handler>; @@ -742,7 +740,6 @@ template class ACE_Unbounded_Queue<ACE_Thread_Descriptor*>; #elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) #pragma instantiate CACHED_CONNECT_STRATEGY -#pragma instantiate HASH_ADDR #pragma instantiate REFCOUNTED_HASH_RECYCLABLE_ADDR #pragma instantiate ACE_NOOP_Creation_Strategy<Svc_Handler> #pragma instantiate ACE_Concurrency_Strategy<Svc_Handler> |