GeezerVison is showing github.com — factorize code for readability · netty/netty@4bbb4e5
File tree
Expand file treeCollapse file tree
Open diff view settings
buffer/src/main/java/io/netty/buffer
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: buffer/src/main/java/io/netty/buffer/AdaptivePoolingAllocator.java +10-8Lines changed: 10 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -534,14 +534,8 @@ public boolean offerChunk(Chunk chunk) { |
534 | 534 | SizeClassedChunk sized = (SizeClassedChunk) chunk; |
535 | 535 | sized.armNotification(); |
536 | 536 | registerToFree(sized); |
537 | | - // Volatile write in armNotification + volatile reads in hasRemainingCapacity: |
538 | | - // SC ordering guarantees at least one side (us or the returning thread) sees |
539 | | - // the other's write — no missed 0→1 transitions on the free list. |
540 | | - if (sized.hasRemainingCapacity()) { |
541 | | - if (SizeClassedChunk.STATE.compareAndSet(sized, SizeClassedChunk.AVAILABLE_ARMED, |
542 | | - SizeClassedChunk.AVAILABLE)) { |
543 | | - notifyReady(sized); |
544 | | - } |
| 537 | + if (sized.disarmIfSegmentsAvailable()) { |
| 538 | + notifyReady(sized); |
545 | 539 | } |
546 | 540 | return true; |
547 | 541 | } |
@@ -1478,6 +1472,14 @@ void armNotification() { |
1478 | 1472 | STATE.set(this, AVAILABLE_ARMED); |
1479 | 1473 | } |
1480 | 1474 |
|
| 1475 | + // Catches segments returned between exhaustion and arming. |
| 1476 | + // SC ordering (volatile write in armNotification + volatile reads here) |
| 1477 | + // guarantees at least one side sees the other's write — no missed 0→1 transitions. |
| 1478 | + boolean disarmIfSegmentsAvailable() { |
| 1479 | + return hasRemainingCapacity() && |
| 1480 | + STATE.compareAndSet(this, AVAILABLE_ARMED, AVAILABLE); |
| 1481 | + } |
| 1482 | + |
1481 | 1483 | @Override |
1482 | 1484 | void releaseSegment(int startIndex, int size) { |
1483 | 1485 | IntStack localFreeList = this.localFreeList; |
|