Made the tag counter a non-static variable.

This was needed to avoid random test failures where a test running
before another could increase the tag and fail the test.
This commit is contained in:
Simone Bordet 2015-03-07 22:35:02 +01:00
parent d63ed9864d
commit 66e1f0a863

View File

@ -119,23 +119,23 @@ public class MappedByteBufferPool implements ByteBufferPool
{ {
return direct ? directBuffers : heapBuffers; return direct ? directBuffers : heapBuffers;
} }
private static AtomicInteger __tag = new AtomicInteger();
public static class Tagged extends MappedByteBufferPool public static class Tagged extends MappedByteBufferPool
{ {
private final AtomicInteger tag = new AtomicInteger();
public ByteBuffer createIndirect(int capacity) public ByteBuffer createIndirect(int capacity)
{ {
ByteBuffer buffer = BufferUtil.allocate(capacity+4); ByteBuffer buffer = BufferUtil.allocate(capacity + 4);
buffer.limit(4); buffer.limit(4);
buffer.putInt(0,__tag.incrementAndGet()); buffer.putInt(0, tag.incrementAndGet());
buffer.position(4); buffer.position(4);
buffer.limit(buffer.capacity()); buffer.limit(buffer.capacity());
ByteBuffer slice = buffer.slice(); ByteBuffer slice = buffer.slice();
BufferUtil.clear(slice); BufferUtil.clear(slice);
return slice; return slice;
} }
protected ByteBuffer createDirect(int capacity) protected ByteBuffer createDirect(int capacity)
{ {
return createIndirect(capacity); return createIndirect(capacity);