Simplify Calldepththreadlocalmap to not use atomic integers
This commit is contained in:
parent
9174c7804c
commit
3187f7350f
|
@ -2,7 +2,6 @@ package datadog.trace.bootstrap;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility to track nested instrumentation.
|
* Utility to track nested instrumentation.
|
||||||
|
@ -11,30 +10,27 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||||
* #incrementCallDepth at the beginning of each constructor.
|
* #incrementCallDepth at the beginning of each constructor.
|
||||||
*/
|
*/
|
||||||
public class CallDepthThreadLocalMap {
|
public class CallDepthThreadLocalMap {
|
||||||
private static final ThreadLocal<Map<Object, AtomicInteger>> TLS =
|
private static final ThreadLocal<Map<Object, Integer>> TLS =
|
||||||
new ThreadLocal<Map<Object, AtomicInteger>>() {
|
new ThreadLocal<Map<Object, Integer>>() {
|
||||||
@Override
|
@Override
|
||||||
public Map<Object, AtomicInteger> initialValue() {
|
public Map<Object, Integer> initialValue() {
|
||||||
return new HashMap<>();
|
return new HashMap<>();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public static int incrementCallDepth(final Object k) {
|
public static int incrementCallDepth(final Object k) {
|
||||||
final Map<Object, AtomicInteger> map = TLS.get();
|
final Map<Object, Integer> map = TLS.get();
|
||||||
AtomicInteger depth = map.get(k);
|
Integer depth = map.get(k);
|
||||||
if (depth == null) {
|
if (depth == null) {
|
||||||
depth = new AtomicInteger(0);
|
depth = 0;
|
||||||
map.put(k, depth);
|
|
||||||
return 0;
|
|
||||||
} else {
|
} else {
|
||||||
return depth.incrementAndGet();
|
depth += 1;
|
||||||
}
|
}
|
||||||
|
map.put(k, depth);
|
||||||
|
return depth;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void reset(final Object k) {
|
public static void reset(final Object k) {
|
||||||
final Map<Object, AtomicInteger> map = TLS.get();
|
TLS.get().remove(k);
|
||||||
if (map != null) {
|
|
||||||
map.remove(k);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue