diff options
author | Michi Henning <michi@zeroc.com> | 2006-02-21 04:08:40 +0000 |
---|---|---|
committer | Michi Henning <michi@zeroc.com> | 2006-02-21 04:08:40 +0000 |
commit | 17637b2c90916a65a844ab39a0efe7aadc590fdc (patch) | |
tree | ef5474109fd55f1778f395abc120fa3260148405 | |
parent | Bug 867. (diff) | |
download | ice-17637b2c90916a65a844ab39a0efe7aadc590fdc.tar.bz2 ice-17637b2c90916a65a844ab39a0efe7aadc590fdc.tar.xz ice-17637b2c90916a65a844ab39a0efe7aadc590fdc.zip |
Bug 857.
-rw-r--r-- | cpp/src/Ice/Reference.cpp | 25 | ||||
-rw-r--r-- | cpp/src/Ice/Reference.h | 16 | ||||
-rw-r--r-- | cppe/src/IceE/Reference.cpp | 24 | ||||
-rw-r--r-- | cppe/src/IceE/Reference.h | 24 | ||||
-rwxr-xr-x | cs/src/Ice/Reference.cs | 15 | ||||
-rw-r--r-- | java/src/IceInternal/IndirectReference.java | 16 | ||||
-rw-r--r-- | java/src/IceInternal/Reference.java | 6 | ||||
-rw-r--r-- | java/src/IceInternal/RoutableReference.java | 6 | ||||
-rw-r--r-- | javae/src/IceInternal/IndirectReference.java | 16 | ||||
-rw-r--r-- | javae/src/IceInternal/Reference.java | 6 | ||||
-rw-r--r-- | javae/src/IceInternal/RoutableReference.java | 6 |
11 files changed, 135 insertions, 25 deletions
diff --git a/cpp/src/Ice/Reference.cpp b/cpp/src/Ice/Reference.cpp index 6ebe481ea3f..0a84aced76c 100644 --- a/cpp/src/Ice/Reference.cpp +++ b/cpp/src/Ice/Reference.cpp @@ -118,7 +118,7 @@ IceInternal::Reference::changeEndpointSelection(EndpointSelectionType newType) c Int Reference::hash() const { - IceUtil::Mutex::Lock sync(_hashMutex); + IceUtil::RecMutex::Lock sync(_hashMutex); if(_hashInitialized) { @@ -759,6 +759,12 @@ IceInternal::RoutableReference::changeCollocationOptimization(bool newCollocatio return r; } +int +IceInternal::RoutableReference::hash() const +{ + return Reference::hash(); +} + bool IceInternal::RoutableReference::operator==(const Reference& r) const { @@ -1469,6 +1475,23 @@ IceInternal::IndirectReference::getConnection(bool& comp) const return connection; } +int +IceInternal::IndirectReference::hash() const +{ + IceUtil::RecMutex::Lock sync(_hashMutex); + + if(_hashInitialized) + { + return _hashValue; + } + RoutableReference::hash(); // Initializes _hashValue. + for(string::const_iterator p = _adapterId.begin(); p != _adapterId.end(); ++p) // Add hash of adapter ID to base hash. + { + _hashValue = 5 * _hashValue + *p; + } + return _hashValue; +} + bool IceInternal::IndirectReference::operator==(const Reference& r) const { diff --git a/cpp/src/Ice/Reference.h b/cpp/src/Ice/Reference.h index 7d7d55a2856..7f67f2aa41c 100644 --- a/cpp/src/Ice/Reference.h +++ b/cpp/src/Ice/Reference.h @@ -11,7 +11,7 @@ #define ICE_REFERENCE_H #include <IceUtil/Shared.h> -#include <IceUtil/Mutex.h> +#include <IceUtil/RecMutex.h> #include <Ice/ReferenceF.h> #include <Ice/ReferenceFactoryF.h> #include <Ice/EndpointIF.h> @@ -83,7 +83,7 @@ public: virtual ReferencePtr changeEndpoints(const std::vector<EndpointIPtr>&) const = 0; virtual ReferencePtr changeLocatorCacheTimeout(int) const = 0; - int hash() const; // Conceptually const. + virtual int hash() const; // Conceptually const. // // Marshal the reference. @@ -112,6 +112,10 @@ protected: const std::string&, Mode); Reference(const Reference&); + IceUtil::RecMutex _hashMutex; // For lazy initialization of hash value. + mutable Ice::Int _hashValue; + mutable bool _hashInitialized; + private: const InstancePtr _instance; @@ -123,10 +127,6 @@ private: std::string _facet; bool _cacheConnection; Ice::EndpointSelectionType _endpointSelection; - - IceUtil::Mutex _hashMutex; // For lazy initialization of hash value. - mutable Ice::Int _hashValue; - mutable bool _hashInitialized; }; class FixedReference : public Reference @@ -193,6 +193,8 @@ public: virtual Ice::ConnectionIPtr getConnection(bool&) const = 0; + virtual int hash() const; + virtual bool operator==(const Reference&) const = 0; virtual bool operator!=(const Reference&) const = 0; virtual bool operator<(const Reference&) const = 0; @@ -278,6 +280,8 @@ public: virtual std::string toString() const; virtual Ice::ConnectionIPtr getConnection(bool&) const; + virtual int hash() const; // Conceptually const. + virtual bool operator==(const Reference&) const; virtual bool operator!=(const Reference&) const; virtual bool operator<(const Reference&) const; diff --git a/cppe/src/IceE/Reference.cpp b/cppe/src/IceE/Reference.cpp index 26aaa044409..234ec78dd71 100644 --- a/cppe/src/IceE/Reference.cpp +++ b/cppe/src/IceE/Reference.cpp @@ -106,7 +106,7 @@ IceInternal::Reference::changeFacet(const string& newFacet) const Int Reference::hash() const { - IceUtil::Mutex::Lock sync(_hashMutex); + IceUtil::RecMutex::Lock sync(_hashMutex); if(_hashInitialized) { @@ -590,6 +590,11 @@ IceInternal::RoutableReference::changeRouter(const RouterPrx& newRouter) const return r; } +int +IceInternal::RoutableReference::hash() const +{ + return Reference::hash(); +} bool IceInternal::RoutableReference::operator==(const Reference& r) const @@ -1050,6 +1055,23 @@ IceInternal::IndirectReference::getConnection() const return connection; } +int +IceInternal::IndirectReference::hash() const +{ + IceUtil::RecMutex::Lock sync(_hashMutex); + + if(_hashInitialized) + { + return _hashValue; + } + RoutableReference::hash(); // Initializes _hashValue. + for(string::const_iterator p = _adapterId.begin(); p != _adapterId.end(); ++p) // Add hash of adapter ID to base hash. + { + _hashValue = 5 * _hashValue + *p; + } + return _hashValue; +} + bool IceInternal::IndirectReference::operator==(const Reference& r) const { diff --git a/cppe/src/IceE/Reference.h b/cppe/src/IceE/Reference.h index 9380a25836a..11854d17fb8 100644 --- a/cppe/src/IceE/Reference.h +++ b/cppe/src/IceE/Reference.h @@ -24,7 +24,7 @@ #endif #include <IceE/ConnectionF.h> #include <IceE/Shared.h> -#include <IceE/Mutex.h> +#include <IceE/RecMutex.h> #include <IceE/Identity.h> namespace IceInternal @@ -106,6 +106,10 @@ protected: const std::string&, Mode, bool); Reference(const Reference&); + IceUtil::RecMutex _hashMutex; // For lazy initialization of hash value. + mutable Ice::Int _hashValue; + mutable bool _hashInitialized; + private: const InstancePtr _instance; @@ -116,10 +120,6 @@ private: Ice::Identity _identity; Ice::Context _context; std::string _facet; - - IceUtil::Mutex _hashMutex; // For lazy initialization of hash value. - mutable Ice::Int _hashValue; - mutable bool _hashInitialized; }; class FixedReference : public Reference @@ -173,6 +173,8 @@ public: virtual Ice::ConnectionPtr getConnection() const = 0; + int hash() const; // Conceptually const. + virtual bool operator==(const Reference&) const = 0; virtual bool operator!=(const Reference&) const = 0; virtual bool operator<(const Reference&) const = 0; @@ -272,6 +274,8 @@ public: virtual std::string toString() const; virtual Ice::ConnectionPtr getConnection() const; + int hash() const; // Conceptually const. + virtual bool operator==(const Reference&) const; virtual bool operator!=(const Reference&) const; virtual bool operator<(const Reference&) const; @@ -286,11 +290,11 @@ private: std::string _adapterId; LocatorInfoPtr _locatorInfo; -#ifdef ICEE_HAS_ROUTER
- typedef RoutableReference Parent;
-#else
- typedef Reference Parent;
-#endif
+#ifdef ICEE_HAS_ROUTER + typedef RoutableReference Parent; +#else + typedef Reference Parent; +#endif }; #endif // ICEE_HAS_LOCATOR diff --git a/cs/src/Ice/Reference.cs b/cs/src/Ice/Reference.cs index 8585861a65c..3c3f32e6262 100755 --- a/cs/src/Ice/Reference.cs +++ b/cs/src/Ice/Reference.cs @@ -1471,7 +1471,20 @@ namespace IceInternal // public override int GetHashCode() { - return base.GetHashCode(); + lock(this) + { + if(base.hashInitialized_) + { + return hashValue_; + } + base.GetHashCode(); // Initializes hashValue_. + int sz = adapterId_.Length; // Add hash of adapter ID to base hash. + for(int i = 0; i < sz; i++) + { + hashValue_ = 5 * hashValue_ + (int)adapterId_[i]; + } + return hashValue_; + } } private string adapterId_; diff --git a/java/src/IceInternal/IndirectReference.java b/java/src/IceInternal/IndirectReference.java index a1a563240cb..8c238f41f9f 100644 --- a/java/src/IceInternal/IndirectReference.java +++ b/java/src/IceInternal/IndirectReference.java @@ -273,6 +273,22 @@ public class IndirectReference extends RoutableReference return connection; } + public synchronized int + hashCode() + { + if(_hashInitialized) + { + return _hashValue; + } + super.hashCode(); // Initializes _hashValue. + int sz = _adapterId.length(); // Add hash of adapter ID to base hash. + for(int i = 0; i < sz; i++) + { + _hashValue = 5 * _hashValue + (int)_adapterId.charAt(i); + } + return _hashValue; + } + public boolean equals(java.lang.Object obj) { diff --git a/java/src/IceInternal/Reference.java b/java/src/IceInternal/Reference.java index 7c81088d05d..46d24798b4c 100644 --- a/java/src/IceInternal/Reference.java +++ b/java/src/IceInternal/Reference.java @@ -175,7 +175,7 @@ public abstract class Reference implements Cloneable public abstract Reference changeEndpoints(EndpointI[] newEndpoints); public abstract Reference changeLocatorCacheTimeout(int newTimeout); - public final synchronized int + public synchronized int hashCode() { if(_hashInitialized) @@ -404,8 +404,8 @@ public abstract class Reference implements Cloneable private boolean _cacheConnection; private Ice.EndpointSelectionType _endpointSelection; - private int _hashValue; - private boolean _hashInitialized; + protected int _hashValue; + protected boolean _hashInitialized; protected Reference(Instance inst, diff --git a/java/src/IceInternal/RoutableReference.java b/java/src/IceInternal/RoutableReference.java index f515adaeb7b..2756b43d86c 100644 --- a/java/src/IceInternal/RoutableReference.java +++ b/java/src/IceInternal/RoutableReference.java @@ -81,6 +81,12 @@ public abstract class RoutableReference extends Reference return r; } + public synchronized int + hashCode() + { + return super.hashCode(); + } + public boolean equals(java.lang.Object obj) { diff --git a/javae/src/IceInternal/IndirectReference.java b/javae/src/IceInternal/IndirectReference.java index be0280dd925..9ddabbd9aa2 100644 --- a/javae/src/IceInternal/IndirectReference.java +++ b/javae/src/IceInternal/IndirectReference.java @@ -206,6 +206,22 @@ public class IndirectReference extends RoutableReference return connection; } + public synchronized int + hashCode() + { + if(_hashInitialized) + { + return _hashValue; + } + super.hashCode(); // Initializes _hashValue. + int sz = _adapterId.length(); // Add hash of adapter ID to base hash. + for(int i = 0; i < sz; i++) + { + _hashValue = 5 * _hashValue + (int)_adapterId.charAt(i); + } + return _hashValue; + } + public boolean equals(java.lang.Object obj) { diff --git a/javae/src/IceInternal/Reference.java b/javae/src/IceInternal/Reference.java index 93608d23eab..14a62c0bb63 100644 --- a/javae/src/IceInternal/Reference.java +++ b/javae/src/IceInternal/Reference.java @@ -151,7 +151,7 @@ public abstract class Reference public abstract Reference changeLocator(Ice.LocatorPrx newLocator); public abstract Reference changeTimeout(int newTimeout); - public final synchronized int + public synchronized int hashCode() { if(_hashInitialized) @@ -380,8 +380,8 @@ public abstract class Reference private static java.util.Hashtable _emptyContext = new java.util.Hashtable(); private String _facet; - private int _hashValue; - private boolean _hashInitialized; + protected int _hashValue; + protected boolean _hashInitialized; protected Reference() diff --git a/javae/src/IceInternal/RoutableReference.java b/javae/src/IceInternal/RoutableReference.java index 4f9493db86b..13220040e46 100644 --- a/javae/src/IceInternal/RoutableReference.java +++ b/javae/src/IceInternal/RoutableReference.java @@ -46,6 +46,12 @@ public abstract class RoutableReference extends Reference return r; } + public synchronized int + hashCode() + { + return super.hashCode(); + } + public boolean equals(java.lang.Object obj) { |