Make use of AtomicLongFieldUpdater.addAndGet(...) for cleaner code
Motivation: The code in ChannelOutboundBuffer can be simplified by using AtomicLongFieldUpdater.addAndGet(...) Modification: Replace our manual looping with AtomicLongFieldUpdater.addAndGet(...) Result: Cleaner code
This commit is contained in:
parent
2c7ecb444d
commit
9160ceb921
@ -215,16 +215,8 @@ public class ChannelOutboundBuffer {
|
||||
return;
|
||||
}
|
||||
|
||||
long oldValue = totalPendingSize;
|
||||
long newWriteBufferSize = oldValue + size;
|
||||
while (!TOTAL_PENDING_SIZE_UPDATER.compareAndSet(this, oldValue, newWriteBufferSize)) {
|
||||
oldValue = totalPendingSize;
|
||||
newWriteBufferSize = oldValue + size;
|
||||
}
|
||||
|
||||
int highWaterMark = channel.config().getWriteBufferHighWaterMark();
|
||||
|
||||
if (newWriteBufferSize > highWaterMark) {
|
||||
long newWriteBufferSize = TOTAL_PENDING_SIZE_UPDATER.addAndGet(this, size);
|
||||
if (newWriteBufferSize > channel.config().getWriteBufferHighWaterMark()) {
|
||||
if (WRITABLE_UPDATER.compareAndSet(this, 1, 0)) {
|
||||
channel.pipeline().fireChannelWritabilityChanged();
|
||||
}
|
||||
@ -243,16 +235,8 @@ public class ChannelOutboundBuffer {
|
||||
return;
|
||||
}
|
||||
|
||||
long oldValue = totalPendingSize;
|
||||
long newWriteBufferSize = oldValue - size;
|
||||
while (!TOTAL_PENDING_SIZE_UPDATER.compareAndSet(this, oldValue, newWriteBufferSize)) {
|
||||
oldValue = totalPendingSize;
|
||||
newWriteBufferSize = oldValue - size;
|
||||
}
|
||||
|
||||
int lowWaterMark = channel.config().getWriteBufferLowWaterMark();
|
||||
|
||||
if (newWriteBufferSize == 0 || newWriteBufferSize < lowWaterMark) {
|
||||
long newWriteBufferSize = TOTAL_PENDING_SIZE_UPDATER.addAndGet(this, -size);
|
||||
if (newWriteBufferSize == 0 || newWriteBufferSize < channel.config().getWriteBufferLowWaterMark()) {
|
||||
if (WRITABLE_UPDATER.compareAndSet(this, 0, 1)) {
|
||||
channel.pipeline().fireChannelWritabilityChanged();
|
||||
}
|
||||
@ -436,12 +420,7 @@ public class ChannelOutboundBuffer {
|
||||
|
||||
// Just decrease; do not trigger any events via decrementPendingOutboundBytes()
|
||||
int size = e.pendingSize;
|
||||
long oldValue = totalPendingSize;
|
||||
long newWriteBufferSize = oldValue - size;
|
||||
while (!TOTAL_PENDING_SIZE_UPDATER.compareAndSet(this, oldValue, newWriteBufferSize)) {
|
||||
oldValue = totalPendingSize;
|
||||
newWriteBufferSize = oldValue - size;
|
||||
}
|
||||
TOTAL_PENDING_SIZE_UPDATER.addAndGet(this, -size);
|
||||
|
||||
e.pendingSize = 0;
|
||||
if (!e.cancelled) {
|
||||
|
Loading…
Reference in New Issue
Block a user