summaryrefslogtreecommitdiff
path: root/cpp/src/IceGrid/Allocatable.cpp
diff options
context:
space:
mode:
authorBenoit Foucher <benoit@zeroc.com>2006-09-28 15:49:57 +0000
committerBenoit Foucher <benoit@zeroc.com>2006-09-28 15:49:57 +0000
commite5ffa6fee5a138d36d8aa202aeaea621c68e9514 (patch)
tree28027b53b5b6888fc14e02244677e694f1fb57d4 /cpp/src/IceGrid/Allocatable.cpp
parentFixed bug 1417 (diff)
downloadice-e5ffa6fee5a138d36d8aa202aeaea621c68e9514.tar.bz2
ice-e5ffa6fee5a138d36d8aa202aeaea621c68e9514.tar.xz
ice-e5ffa6fee5a138d36d8aa202aeaea621c68e9514.zip
Fixed allocation bug
Diffstat (limited to 'cpp/src/IceGrid/Allocatable.cpp')
-rw-r--r--cpp/src/IceGrid/Allocatable.cpp62
1 files changed, 41 insertions, 21 deletions
diff --git a/cpp/src/IceGrid/Allocatable.cpp b/cpp/src/IceGrid/Allocatable.cpp
index 8c567b94119..9efa9d47c07 100644
--- a/cpp/src/IceGrid/Allocatable.cpp
+++ b/cpp/src/IceGrid/Allocatable.cpp
@@ -259,14 +259,17 @@ Allocatable::release(const SessionIPtr& session, bool fromRelease)
while(true)
{
AllocationRequestPtr request;
- AllocatablePtr allocatable = dequeueAllocationAttempt(request);
- if(!allocatable)
+ AllocatablePtr allocatable;
{
Lock sync(*this);
- assert(_count == 0 && _requests.empty());
- _releasing = false;
- notifyAll();
- return;
+ allocatable = dequeueAllocationAttempt(request);
+ if(!allocatable)
+ {
+ assert(_count == 0 && _requests.empty());
+ _releasing = false;
+ notifyAll();
+ return;
+ }
}
//
@@ -350,17 +353,26 @@ Allocatable::queueAllocationAttempt(const AllocatablePtr& allocatable,
}
else
{
- if(_attempts.insert(allocatable).second)
- {
- _requests.push_back(make_pair(allocatable, AllocationRequestPtr()));
- }
+ _requests.push_back(make_pair(allocatable, AllocationRequestPtr()));
}
}
+void
+Allocatable::queueAllocationAttemptFromChild(const AllocatablePtr& allocatable)
+{
+ if(_parent)
+ {
+ _parent->queueAllocationAttemptFromChild(allocatable);
+ return;
+ }
+
+ Lock sync(*this);
+ _requests.push_back(make_pair(allocatable, AllocationRequestPtr()));
+}
+
AllocatablePtr
Allocatable::dequeueAllocationAttempt(AllocationRequestPtr& request)
{
- Lock sync(*this);
if(_requests.empty())
{
return 0;
@@ -372,10 +384,6 @@ Allocatable::dequeueAllocationAttempt(AllocationRequestPtr& request)
{
request = alloc.second;
}
- else
- {
- _attempts.erase(alloc.first);
- }
return alloc.first;
}
@@ -387,6 +395,7 @@ Allocatable::allocate(const AllocationRequestPtr& request, bool tryAllocate, boo
return false;
}
+ bool queueWithParent = false;
int allocationCount = 0;
try
{
@@ -400,7 +409,6 @@ Allocatable::allocate(const AllocationRequestPtr& request, bool tryAllocate, boo
try
{
allocated(request->getSession()); // This might throw SessionDestroyedException
- request->allocated(this, request->getSession());
}
catch(const SessionDestroyedException&)
{
@@ -409,18 +417,26 @@ Allocatable::allocate(const AllocationRequestPtr& request, bool tryAllocate, boo
}
assert(_count == 0);
_session = request->getSession();
+ request->allocated(this, request->getSession());
++_count;
allocationCount = _count;
}
}
else if(_session == request->getSession())
{
- if(!tryAllocate && request->allocate(this, _session))
+ if(!tryAllocate)
{
- assert(_count > 0);
- ++_count;
- request->allocated(this, _session);
- allocationCount = _count;
+ if(request->allocate(this, _session))
+ {
+ assert(_count > 0);
+ ++_count;
+ request->allocated(this, _session);
+ allocationCount = _count;
+ }
+ }
+ else
+ {
+ queueWithParent = true;
}
}
else
@@ -451,6 +467,10 @@ Allocatable::allocate(const AllocationRequestPtr& request, bool tryAllocate, boo
}
else if(allocationCount == 0 && _parent)
{
+ if(queueWithParent)
+ {
+ _parent->queueAllocationAttemptFromChild(this);
+ }
_parent->release(request->getSession(), fromRelease);
}
return allocationCount > 0;