From 8b23c859786a9d444604644fcc70d1d9d7854b8c Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Wed, 20 Mar 2019 08:33:06 +0100 Subject: [PATCH] Remove old internal code that is not used anymore after removing usage of ObjectCleaner (#8956) Motivation: We dont use ObjectCleaner in our FastThreadLocal anymore so we also dont need to take special care to store it there anymore. Modifications: Remove code that is not needed anymore. Result: Code cleanup. --- .../util/concurrent/FastThreadLocal.java | 36 ++----------------- 1 file changed, 3 insertions(+), 33 deletions(-) diff --git a/common/src/main/java/io/netty/util/concurrent/FastThreadLocal.java b/common/src/main/java/io/netty/util/concurrent/FastThreadLocal.java index 16205f7d68..8d71a9d415 100644 --- a/common/src/main/java/io/netty/util/concurrent/FastThreadLocal.java +++ b/common/src/main/java/io/netty/util/concurrent/FastThreadLocal.java @@ -139,33 +139,7 @@ public class FastThreadLocal { return (V) v; } - V value = initialize(threadLocalMap); - registerCleaner(threadLocalMap); - return value; - } - - private void registerCleaner(final InternalThreadLocalMap threadLocalMap) { - Thread current = Thread.currentThread(); - if (FastThreadLocalThread.willCleanupFastThreadLocals(current) || threadLocalMap.isCleanerFlagSet(index)) { - return; - } - - threadLocalMap.setCleanerFlag(index); - - // TODO: We need to find a better way to handle this. - /* - // We will need to ensure we will trigger remove(InternalThreadLocalMap) so everything will be released - // and FastThreadLocal.onRemoval(...) will be called. - ObjectCleaner.register(current, new Runnable() { - @Override - public void run() { - remove(threadLocalMap); - - // It's fine to not call InternalThreadLocalMap.remove() here as this will only be triggered once - // the Thread is collected by GC. In this case the ThreadLocal will be gone away already. - } - }); - */ + return initialize(threadLocalMap); } /** @@ -201,9 +175,7 @@ public class FastThreadLocal { public final void set(V value) { if (value != InternalThreadLocalMap.UNSET) { InternalThreadLocalMap threadLocalMap = InternalThreadLocalMap.get(); - if (setKnownNotUnset(threadLocalMap, value)) { - registerCleaner(threadLocalMap); - } + setKnownNotUnset(threadLocalMap, value); } else { remove(); } @@ -223,12 +195,10 @@ public class FastThreadLocal { /** * @return see {@link InternalThreadLocalMap#setIndexedVariable(int, Object)}. */ - private boolean setKnownNotUnset(InternalThreadLocalMap threadLocalMap, V value) { + private void setKnownNotUnset(InternalThreadLocalMap threadLocalMap, V value) { if (threadLocalMap.setIndexedVariable(index, value)) { addToVariablesToRemove(threadLocalMap, this); - return true; } - return false; } /**