Commit c0281d46 by Corentin Wallez Committed by Commit Bot

HandleAllocator: make HandleRange inclusive.

Previously part of the code saw it as [begin, end) while others saw it as [begin, end]. BUG=angleproject:1052 BUG=chromium:656485 Change-Id: Id8e9e26b167e02a07dfc5341569df53a14d0623d Reviewed-on: https://chromium-review.googlesource.com/399565Reviewed-by: 's avatarZhenyao Mo <zmo@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Commit-Queue: Corentin Wallez <cwallez@chromium.org>
parent 4db7ded5
...@@ -63,11 +63,14 @@ GLuint HandleAllocator::allocate() ...@@ -63,11 +63,14 @@ GLuint HandleAllocator::allocate()
GLuint freeListHandle = listIt->begin; GLuint freeListHandle = listIt->begin;
ASSERT(freeListHandle > 0); ASSERT(freeListHandle > 0);
listIt->begin++;
if (listIt->begin == listIt->end) if (listIt->begin == listIt->end)
{ {
mUnallocatedList.erase(listIt); mUnallocatedList.erase(listIt);
} }
else
{
listIt->begin++;
}
return freeListHandle; return freeListHandle;
} }
...@@ -101,7 +104,7 @@ void HandleAllocator::reserve(GLuint handle) ...@@ -101,7 +104,7 @@ void HandleAllocator::reserve(GLuint handle)
if (handle == begin || handle == end) if (handle == begin || handle == end)
{ {
if (begin + 1 == end) if (begin == end)
{ {
mUnallocatedList.erase(boundIt); mUnallocatedList.erase(boundIt);
} }
...@@ -117,18 +120,12 @@ void HandleAllocator::reserve(GLuint handle) ...@@ -117,18 +120,12 @@ void HandleAllocator::reserve(GLuint handle)
return; return;
} }
ASSERT(begin < handle && handle < end);
// need to split the range // need to split the range
auto placementIt = mUnallocatedList.erase(boundIt); auto placementIt = mUnallocatedList.erase(boundIt);
placementIt = mUnallocatedList.insert(placementIt, HandleRange(handle + 1, end));
if (handle + 1 != end) mUnallocatedList.insert(placementIt, HandleRange(begin, handle - 1));
{
placementIt = mUnallocatedList.insert(placementIt, HandleRange(handle + 1, end));
}
if (begin != handle)
{
ASSERT(begin < handle);
mUnallocatedList.insert(placementIt, HandleRange(begin, handle));
}
} }
} // namespace gl } // namespace gl
...@@ -41,6 +41,7 @@ class HandleAllocator final : angle::NonCopyable ...@@ -41,6 +41,7 @@ class HandleAllocator final : angle::NonCopyable
typedef std::vector<GLuint> HandleList; typedef std::vector<GLuint> HandleList;
HandleList mFreeValues; HandleList mFreeValues;
// Represents an inclusive range [begin, end]
struct HandleRange struct HandleRange
{ {
HandleRange(GLuint beginIn, GLuint endIn) : begin(beginIn), end(endIn) {} HandleRange(GLuint beginIn, GLuint endIn) : begin(beginIn), end(endIn) {}
......
...@@ -90,8 +90,7 @@ TEST(HandleAllocatorTest, Reallocation) ...@@ -90,8 +90,7 @@ TEST(HandleAllocatorTest, Reallocation)
EXPECT_EQ(finalResult, 1); EXPECT_EQ(finalResult, 1);
} }
// The following test covers reserving a handle with max uint value. // The following test covers reserving a handle with max uint value. See http://anglebug.com/1052
// See http://anglebug.com/1052
TEST(HandleAllocatorTest, ReserveMaxUintHandle) TEST(HandleAllocatorTest, ReserveMaxUintHandle)
{ {
gl::HandleAllocator allocator; gl::HandleAllocator allocator;
...@@ -103,6 +102,19 @@ TEST(HandleAllocatorTest, ReserveMaxUintHandle) ...@@ -103,6 +102,19 @@ TEST(HandleAllocatorTest, ReserveMaxUintHandle)
EXPECT_EQ(1u, normalHandle); EXPECT_EQ(1u, normalHandle);
} }
// The following test covers reserving a handle with max uint value minus one then max uint value.
TEST(HandleAllocatorTest, ReserveMaxUintHandle2)
{
gl::HandleAllocator allocator;
GLuint maxUintHandle = std::numeric_limits<GLuint>::max();
allocator.reserve(maxUintHandle - 1);
allocator.reserve(maxUintHandle);
GLuint normalHandle = allocator.allocate();
EXPECT_EQ(1u, normalHandle);
}
// To test if the allocator keep the handle in a sorted order. // To test if the allocator keep the handle in a sorted order.
TEST(HandleAllocatorTest, SortedOrderHandle) TEST(HandleAllocatorTest, SortedOrderHandle)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment