Skip to content

Commit 1c6673a

Browse files
authored
Merge pull request #19 from riptano/DSP-19407-upgrade-review-remarks
DSP-19407 after upgrade review remarks
2 parents 136266b + 1731329 commit 1c6673a

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

common/src/main/java/io/netty/util/concurrent/AbstractScheduledEventExecutor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public int compare(ScheduledFutureTask<?> o1, ScheduledFutureTask<?> o2) {
3838
}
3939
};
4040

41-
PriorityQueue<ScheduledFutureTask<?>> scheduledTaskQueue;
41+
protected PriorityQueue<ScheduledFutureTask<?>> scheduledTaskQueue;
4242

4343
protected AbstractScheduledEventExecutor() {
4444
}

common/src/main/java/io/netty/util/internal/PlatformDependent.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -673,13 +673,15 @@ public static void freeDirectNoCleaner(ByteBuffer buffer) {
673673
}
674674

675675
private static void incrementMemoryCounter(int capacity) {
676-
if (DIRECT_MEMORY_COUNTER != null) {
677-
long newUsedMemory = DIRECT_MEMORY_COUNTER.addAndGet(capacity);
676+
for (;;) {
677+
long usedMemory = DIRECT_MEMORY_COUNTER.get();
678+
long newUsedMemory = usedMemory + capacity;
678679
if (DIRECT_MEMORY_LIMIT > 0 && newUsedMemory > DIRECT_MEMORY_LIMIT) {
679-
DIRECT_MEMORY_COUNTER.addAndGet(-capacity);
680680
throw new OutOfDirectMemoryError("failed to allocate " + capacity
681-
+ " byte(s) of direct memory (used: " + (newUsedMemory - capacity)
682-
+ ", max: " + DIRECT_MEMORY_LIMIT + ')');
681+
+ " byte(s) of direct memory (used: " + usedMemory + ", max: " + DIRECT_MEMORY_LIMIT + ')');
682+
}
683+
if (DIRECT_MEMORY_COUNTER.compareAndSet(usedMemory, newUsedMemory)) {
684+
break;
683685
}
684686
}
685687
}

0 commit comments

Comments
 (0)