HBASE-16146 Remove thread local usage in Counter

This commit is contained in:
Gary Helmling 2016-09-21 17:43:41 -07:00
parent fef3c908d3
commit 7b0acc292e
1 changed files with 1 additions and 20 deletions

View File

@ -110,25 +110,12 @@ public class Counter {
return h;
}
private static class IndexHolder {
int index = hash();
}
private final ThreadLocal<IndexHolder> indexHolderThreadLocal =
new ThreadLocal<IndexHolder>() {
@Override
protected IndexHolder initialValue() {
return new IndexHolder();
}
};
public void add(long delta) {
Container container = containerRef.get();
Cell[] cells = container.cells;
int mask = cells.length - 1;
IndexHolder indexHolder = indexHolderThreadLocal.get();
int baseIndex = indexHolder.index;
int baseIndex = hash();
if(cells[baseIndex & mask].add(delta)) {
return;
}
@ -141,8 +128,6 @@ public class Counter {
index++;
}
indexHolder.index = index;
if(index - baseIndex >= cells.length &&
cells.length < MAX_CELLS_LENGTH &&
container.demoted.compareAndSet(false, true)) {
@ -183,10 +168,6 @@ public class Counter {
return sum;
}
public void destroy() {
indexHolderThreadLocal.remove();
}
@Override
public String toString() {
Cell[] cells = containerRef.get().cells;