[#2924] Correctly update head in MemoryRegionCache.trim()

Motivation:
When MemoryRegionCache.trim() is called, some unused cache entries will be freed (started from head). However, in MeoryRegionCache.trim() the head is not updated, which make entry list's head point to an entry whose chunk is null now and following allocate of MeoryRegionCache will return false immediately.

In other word, cache is no longer usable once trim happen.

Modifications:

Update head to correct idx after free entries in trim().

Result:

MemoryRegionCache behaves correctly even after calling trim().
This commit is contained in:
Norman Maurer 2014-09-22 10:56:17 +02:00
parent 764e6c3bb7
commit 4131e1dfd3

View File

@ -445,10 +445,14 @@ final class PoolThreadCache {
for (; free > 0; free--) {
if (!freeEntry(entries[i])) {
// all freed
return;
break;
}
i = nextIdx(i);
}
// Update head to point to te correct entry
// See https://github.com/netty/netty/issues/2924
head = i;
}
@SuppressWarnings({ "unchecked", "rawtypes" })