aboutsummaryrefslogtreecommitdiff
path: root/kamon-core/src/main/java/kamon/jsr166/LongAdder.java
diff options
context:
space:
mode:
Diffstat (limited to 'kamon-core/src/main/java/kamon/jsr166/LongAdder.java')
-rw-r--r--kamon-core/src/main/java/kamon/jsr166/LongAdder.java15
1 files changed, 15 insertions, 0 deletions
diff --git a/kamon-core/src/main/java/kamon/jsr166/LongAdder.java b/kamon-core/src/main/java/kamon/jsr166/LongAdder.java
index 18f91759..7e47ae63 100644
--- a/kamon-core/src/main/java/kamon/jsr166/LongAdder.java
+++ b/kamon-core/src/main/java/kamon/jsr166/LongAdder.java
@@ -151,6 +151,21 @@ public class LongAdder extends Striped64 implements Serializable {
return sum;
}
+ public long sumAndReset() {
+ long sum = getAndSetBase(0L);
+ Cell[] as = cells;
+ if (as != null) {
+ int n = as.length;
+ for (int i = 0; i < n; ++i) {
+ Cell a = as[i];
+ if (a != null) {
+ sum += a.getAndSet(0L);
+ }
+ }
+ }
+ return sum;
+ }
+
/**
* Returns the String representation of the {@link #sum}.
* @return the String representation of the {@link #sum}