diff options
author | Benoit Foucher <benoit@zeroc.com> | 2006-03-29 08:42:35 +0000 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2006-03-29 08:42:35 +0000 |
commit | f2b162b67c2382a2da555e7a960beaa3ab6b3997 (patch) | |
tree | 5ba1d3a23c1f6ea4e1792f77b762d2fb17bb7bde | |
parent | Fixed invalid implicit conversion (diff) | |
download | ice-f2b162b67c2382a2da555e7a960beaa3ab6b3997.tar.bz2 ice-f2b162b67c2382a2da555e7a960beaa3ab6b3997.tar.xz ice-f2b162b67c2382a2da555e7a960beaa3ab6b3997.zip |
Random fixes.
-rw-r--r-- | cpp/src/Ice/Reference.cpp | 14 | ||||
-rw-r--r-- | cpp/src/Ice/Reference.h | 2 | ||||
-rw-r--r-- | cpp/src/IceGrid/AdapterCache.cpp | 20 | ||||
-rw-r--r-- | cpp/src/IceGrid/AdapterCache.h | 2 | ||||
-rw-r--r-- | cpp/src/IceGrid/Database.cpp | 13 | ||||
-rw-r--r-- | cpp/src/IceGrid/Database.h | 1 | ||||
-rw-r--r-- | cpp/src/IceUtil/Random.cpp | 1 | ||||
-rw-r--r-- | cpp/test/Ice/binding/AllTests.cpp | 50 |
8 files changed, 27 insertions, 76 deletions
diff --git a/cpp/src/Ice/Reference.cpp b/cpp/src/Ice/Reference.cpp index 77275bd8648..29280b2e5b3 100644 --- a/cpp/src/Ice/Reference.cpp +++ b/cpp/src/Ice/Reference.cpp @@ -34,6 +34,8 @@ using namespace IceInternal; void IceInternal::incRef(IceInternal::Reference* p) { p->__incRef(); } void IceInternal::decRef(IceInternal::Reference* p) { p->__decRef(); } +pointer_to_unary_function<int, int> Reference::_rand(IceUtil::random); + CommunicatorPtr IceInternal::Reference::getCommunicator() const { @@ -636,11 +638,7 @@ IceInternal::FixedReference::filterConnections(const vector<ConnectionIPtr>& all // // Randomize the order of connections. // -#ifdef _MSC_VER - random_shuffle(connections.begin(), connections.end(), ptr_fun(IceUtil::random)); -#else - random_shuffle(connections.begin(), connections.end(), IceUtil::random); -#endif + random_shuffle(connections.begin(), connections.end(), _rand); // // If a secure connection is requested, remove all non-secure @@ -936,11 +934,7 @@ IceInternal::RoutableReference::createConnection(const vector<EndpointIPtr>& all { case Random: { -#ifdef _MSC_VER - random_shuffle(endpoints.begin(), endpoints.end(), ptr_fun(IceUtil::random)); -#else - random_shuffle(endpoints.begin(), endpoints.end(), IceUtil::random); -#endif + random_shuffle(endpoints.begin(), endpoints.end(), _rand); break; } case Ordered: diff --git a/cpp/src/Ice/Reference.h b/cpp/src/Ice/Reference.h index 988cfa83bc8..a014666fe10 100644 --- a/cpp/src/Ice/Reference.h +++ b/cpp/src/Ice/Reference.h @@ -116,6 +116,8 @@ protected: mutable Ice::Int _hashValue; mutable bool _hashInitialized; + static std::pointer_to_unary_function<int, int> _rand; + private: const InstancePtr _instance; diff --git a/cpp/src/IceGrid/AdapterCache.cpp b/cpp/src/IceGrid/AdapterCache.cpp index d7f263a349e..00bef5b40a7 100644 --- a/cpp/src/IceGrid/AdapterCache.cpp +++ b/cpp/src/IceGrid/AdapterCache.cpp @@ -18,6 +18,8 @@ using namespace std; using namespace IceGrid; +pointer_to_unary_function<int, int> ReplicaGroupEntry::_rand(IceUtil::random); + namespace IceGrid { @@ -332,17 +334,14 @@ ReplicaGroupEntry::getProxies(bool allRegistered, int& nReplicas) else if(AdaptiveLoadBalancingPolicyPtr::dynamicCast(_loadBalancing)) { replicas = _replicas; + random_shuffle(replicas.begin(), replicas.end(), _rand); adaptive = true; loadSample = _loadSample; } else// if(RandomLoadBalancingPolicyPtr::dynamicCast(_loadBalancing)) { replicas = _replicas; -#ifdef _MSC_VER - random_shuffle(replicas.begin(), replicas.end(), ptr_fun(IceUtil::random)); -#else - random_shuffle(replicas.begin(), replicas.end(), IceUtil::random); -#endif + random_shuffle(replicas.begin(), replicas.end(), _rand); } } @@ -352,11 +351,6 @@ ReplicaGroupEntry::getProxies(bool allRegistered, int& nReplicas) // This must be done outside the synchronization block since // the sort() will call and lock each server entry. // -#ifdef _MSC_VER - random_shuffle(replicas.begin(), replicas.end(), ptr_fun(IceUtil::random)); -#else - random_shuffle(replicas.begin(), replicas.end(), IceUtil::random); -#endif sort(replicas.begin(), replicas.end(), ServerLoadCI(loadSample)); } @@ -399,11 +393,7 @@ ReplicaGroupEntry::getLeastLoadedNodeLoad(LoadSample loadSample) const // This must be done outside the synchronization block since // min_element() will call and lock each server entry. // -#ifdef _MSC_VER - random_shuffle(replicas.begin(), replicas.end(), ptr_fun(IceUtil::random)); -#else - random_shuffle(replicas.begin(), replicas.end(), IceUtil::random); -#endif + random_shuffle(replicas.begin(), replicas.end(), _rand); AdapterEntryPtr adpt = min_element(replicas.begin(), replicas.end(), ServerLoadCI(loadSample))->second; return adpt->getLeastLoadedNodeLoad(loadSample); } diff --git a/cpp/src/IceGrid/AdapterCache.h b/cpp/src/IceGrid/AdapterCache.h index de3c9626647..7fa3169d211 100644 --- a/cpp/src/IceGrid/AdapterCache.h +++ b/cpp/src/IceGrid/AdapterCache.h @@ -94,6 +94,8 @@ private: typedef std::vector<std::pair<std::string, ServerAdapterEntryPtr> > ReplicaSeq; ReplicaSeq _replicas; int _lastReplica; + + static std::pointer_to_unary_function<int, int> _rand; }; typedef IceUtil::Handle<ReplicaGroupEntry> ReplicaGroupEntryPtr; diff --git a/cpp/src/IceGrid/Database.cpp b/cpp/src/IceGrid/Database.cpp index 9e270c2ff40..8a62f3c0ef0 100644 --- a/cpp/src/IceGrid/Database.cpp +++ b/cpp/src/IceGrid/Database.cpp @@ -26,6 +26,7 @@ using namespace IceGrid; const string Database::_descriptorDbName = "applications"; const string Database::_adapterDbName = "adapters"; const string Database::_objectDbName = "objects"; +pointer_to_unary_function<int, int> Database::_rand(IceUtil::random); namespace IceGrid { @@ -766,11 +767,7 @@ Database::getAdapters(const string& id, bool allRegistered, int& endpointCount) adpts.push_back(make_pair(p->first, adpt)); ++p; } -#ifdef _MSC_VER - random_shuffle(adpts.begin(), adpts.end(), ptr_fun(IceUtil::random)); -#else - random_shuffle(adpts.begin(), adpts.end(), IceUtil::random); -#endif + random_shuffle(adpts.begin(), adpts.end(), _rand); endpointCount = static_cast<int>(adpts.size()); return adpts; } @@ -939,11 +936,7 @@ Ice::ObjectPrx Database::getObjectByTypeOnLeastLoadedNode(const string& type, LoadSample sample) { Ice::ObjectProxySeq objs = getObjectsByType(type); -#ifdef _MSC_VER - random_shuffle(objs.begin(), objs.end(), ptr_fun(IceUtil::random)); -#else - random_shuffle(objs.begin(), objs.end(), IceUtil::random); -#endif + random_shuffle(objs.begin(), objs.end(), _rand); vector<pair<Ice::ObjectPrx, float> > objectsWithLoad; objectsWithLoad.reserve(objs.size()); for(Ice::ObjectProxySeq::const_iterator p = objs.begin(); p != objs.end(); ++p) diff --git a/cpp/src/IceGrid/Database.h b/cpp/src/IceGrid/Database.h index bea35189e12..10d4d3c3e59 100644 --- a/cpp/src/IceGrid/Database.h +++ b/cpp/src/IceGrid/Database.h @@ -117,6 +117,7 @@ private: static const std::string _objectDbName; static const std::string _adapterDbName; static const std::string _replicaGroupDbName; + static std::pointer_to_unary_function<int, int> _rand; const Ice::CommunicatorPtr _communicator; const Ice::ObjectAdapterPtr _internalAdapter; diff --git a/cpp/src/IceUtil/Random.cpp b/cpp/src/IceUtil/Random.cpp index 79b6eb32103..a3dc24c5f5e 100644 --- a/cpp/src/IceUtil/Random.cpp +++ b/cpp/src/IceUtil/Random.cpp @@ -14,7 +14,6 @@ #else # include <IceUtil/StaticMutex.h> # include <fcntl.h> -# include <unistd.h> #endif using namespace std; diff --git a/cpp/test/Ice/binding/AllTests.cpp b/cpp/test/Ice/binding/AllTests.cpp index 95044bcb957..d23e905d26b 100644 --- a/cpp/test/Ice/binding/AllTests.cpp +++ b/cpp/test/Ice/binding/AllTests.cpp @@ -15,6 +15,8 @@ using namespace std; using namespace Test; +static pointer_to_unary_function<int, int> randomGenerator(IceUtil::random); + class GetAdapterNameCB : public AMI_TestIntf_getAdapterName, public IceUtil::Monitor<IceUtil::Mutex> { public: @@ -136,17 +138,9 @@ allTests(const Ice::CommunicatorPtr& communicator) vector<RemoteObjectAdapterPrx> adpts = adapters; TestIntfPrx test1 = createTestIntfPrx(adpts); -#ifdef _MSC_VER - random_shuffle(adpts.begin(), adpts.end(), ptr_fun(IceUtil::random)); -#else - random_shuffle(adpts.begin(), adpts.end(), IceUtil::random); -#endif + random_shuffle(adpts.begin(), adpts.end(), randomGenerator); TestIntfPrx test2 = createTestIntfPrx(adpts); -#ifdef _MSC_VER - random_shuffle(adpts.begin(), adpts.end(), ptr_fun(IceUtil::random)); -#else - random_shuffle(adpts.begin(), adpts.end(), IceUtil::random); -#endif + random_shuffle(adpts.begin(), adpts.end(), randomGenerator); TestIntfPrx test3 = createTestIntfPrx(adpts); test(test1->ice_connection() == test2->ice_connection()); @@ -191,17 +185,9 @@ allTests(const Ice::CommunicatorPtr& communicator) vector<RemoteObjectAdapterPrx> adpts = adapters; TestIntfPrx test1 = createTestIntfPrx(adpts); -#ifdef _MSC_VER - random_shuffle(adpts.begin(), adpts.end(), ptr_fun(IceUtil::random)); -#else - random_shuffle(adpts.begin(), adpts.end(), IceUtil::random); -#endif + random_shuffle(adpts.begin(), adpts.end(), randomGenerator); TestIntfPrx test2 = createTestIntfPrx(adpts); -#ifdef _MSC_VER - random_shuffle(adpts.begin(), adpts.end(), ptr_fun(IceUtil::random)); -#else - random_shuffle(adpts.begin(), adpts.end(), IceUtil::random); -#endif + random_shuffle(adpts.begin(), adpts.end(), randomGenerator); TestIntfPrx test3 = createTestIntfPrx(adpts); test(test1->ice_connection() == test2->ice_connection()); @@ -243,17 +229,9 @@ allTests(const Ice::CommunicatorPtr& communicator) vector<RemoteObjectAdapterPrx> adpts = adapters; TestIntfPrx test1 = createTestIntfPrx(adpts); -#ifdef _MSC_VER - random_shuffle(adpts.begin(), adpts.end(), ptr_fun(IceUtil::random)); -#else - random_shuffle(adpts.begin(), adpts.end(), IceUtil::random); -#endif + random_shuffle(adpts.begin(), adpts.end(), randomGenerator); TestIntfPrx test2 = createTestIntfPrx(adpts); -#ifdef _MSC_VER - random_shuffle(adpts.begin(), adpts.end(), ptr_fun(IceUtil::random)); -#else - random_shuffle(adpts.begin(), adpts.end(), IceUtil::random); -#endif + random_shuffle(adpts.begin(), adpts.end(), randomGenerator); TestIntfPrx test3 = createTestIntfPrx(adpts); test(test1->ice_connection() == test2->ice_connection()); @@ -298,17 +276,9 @@ allTests(const Ice::CommunicatorPtr& communicator) vector<RemoteObjectAdapterPrx> adpts = adapters; TestIntfPrx test1 = createTestIntfPrx(adpts); -#ifdef _MSC_VER - random_shuffle(adpts.begin(), adpts.end(), ptr_fun(IceUtil::random)); -#else - random_shuffle(adpts.begin(), adpts.end(), IceUtil::random); -#endif + random_shuffle(adpts.begin(), adpts.end(), randomGenerator); TestIntfPrx test2 = createTestIntfPrx(adpts); -#ifdef _MSC_VER - random_shuffle(adpts.begin(), adpts.end(), ptr_fun(IceUtil::random)); -#else - random_shuffle(adpts.begin(), adpts.end(), IceUtil::random); -#endif + random_shuffle(adpts.begin(), adpts.end(), randomGenerator); TestIntfPrx test3 = createTestIntfPrx(adpts); test(test1->ice_connection() == test2->ice_connection()); |