summaryrefslogtreecommitdiff
path: root/cpp/src/IceGrid
diff options
context:
space:
mode:
authorBenoit Foucher <benoit@zeroc.com>2006-03-29 08:42:35 +0000
committerBenoit Foucher <benoit@zeroc.com>2006-03-29 08:42:35 +0000
commitf2b162b67c2382a2da555e7a960beaa3ab6b3997 (patch)
tree5ba1d3a23c1f6ea4e1792f77b762d2fb17bb7bde /cpp/src/IceGrid
parentFixed invalid implicit conversion (diff)
downloadice-f2b162b67c2382a2da555e7a960beaa3ab6b3997.tar.bz2
ice-f2b162b67c2382a2da555e7a960beaa3ab6b3997.tar.xz
ice-f2b162b67c2382a2da555e7a960beaa3ab6b3997.zip
Random fixes.
Diffstat (limited to 'cpp/src/IceGrid')
-rw-r--r--cpp/src/IceGrid/AdapterCache.cpp20
-rw-r--r--cpp/src/IceGrid/AdapterCache.h2
-rw-r--r--cpp/src/IceGrid/Database.cpp13
-rw-r--r--cpp/src/IceGrid/Database.h1
4 files changed, 11 insertions, 25 deletions
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;