Also allow to override how direct ByteBuffers are freed

This commit is contained in:
Norman Maurer 2013-11-12 12:40:41 +01:00
parent 9b7d286652
commit d11d3a6b50
2 changed files with 18 additions and 4 deletions

View File

@ -109,13 +109,20 @@ public class UnpooledDirectByteBuf extends AbstractReferenceCountedByteBuf {
return ByteBuffer.allocateDirect(initialCapacity); return ByteBuffer.allocateDirect(initialCapacity);
} }
/**
* Free a direct {@link ByteBuffer}
*/
protected void freeDirect(ByteBuffer buffer) {
PlatformDependent.freeDirectBuffer(buffer);
}
private void setByteBuffer(ByteBuffer buffer) { private void setByteBuffer(ByteBuffer buffer) {
ByteBuffer oldBuffer = this.buffer; ByteBuffer oldBuffer = this.buffer;
if (oldBuffer != null) { if (oldBuffer != null) {
if (doNotFree) { if (doNotFree) {
doNotFree = false; doNotFree = false;
} else { } else {
PlatformDependent.freeDirectBuffer(oldBuffer); freeDirect(oldBuffer);
} }
} }
@ -595,7 +602,7 @@ public class UnpooledDirectByteBuf extends AbstractReferenceCountedByteBuf {
this.buffer = null; this.buffer = null;
if (!doNotFree) { if (!doNotFree) {
PlatformDependent.freeDirectBuffer(buffer); freeDirect(buffer);
} }
if (leak != null) { if (leak != null) {

View File

@ -112,13 +112,20 @@ public class UnpooledUnsafeDirectByteBuf extends AbstractReferenceCountedByteBuf
return ByteBuffer.allocateDirect(initialCapacity); return ByteBuffer.allocateDirect(initialCapacity);
} }
/**
* Free a direct {@link ByteBuffer}
*/
protected void freeDirect(ByteBuffer buffer) {
PlatformDependent.freeDirectBuffer(buffer);
}
private void setByteBuffer(ByteBuffer buffer) { private void setByteBuffer(ByteBuffer buffer) {
ByteBuffer oldBuffer = this.buffer; ByteBuffer oldBuffer = this.buffer;
if (oldBuffer != null) { if (oldBuffer != null) {
if (doNotFree) { if (doNotFree) {
doNotFree = false; doNotFree = false;
} else { } else {
PlatformDependent.freeDirectBuffer(oldBuffer); freeDirect(oldBuffer);
} }
} }
@ -495,7 +502,7 @@ public class UnpooledUnsafeDirectByteBuf extends AbstractReferenceCountedByteBuf
this.buffer = null; this.buffer = null;
if (!doNotFree) { if (!doNotFree) {
PlatformDependent.freeDirectBuffer(buffer); freeDirect(buffer);
} }
if (leak != null) { if (leak != null) {