cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject [02/16] git commit: replace volatile regionCount w/ AtomicInteger
Date Thu, 08 Aug 2013 16:33:55 GMT
replace volatile regionCount w/ AtomicInteger


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/f022354c
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/f022354c
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/f022354c

Branch: refs/heads/trunk
Commit: f022354cb44a15d034b3a28dec5d38cc97084faf
Parents: 23becce
Author: Jonathan Ellis <jbellis@apache.org>
Authored: Thu Aug 8 10:57:48 2013 -0500
Committer: Jonathan Ellis <jbellis@apache.org>
Committed: Thu Aug 8 10:57:48 2013 -0500

----------------------------------------------------------------------
 src/java/org/apache/cassandra/utils/SlabAllocator.java | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/f022354c/src/java/org/apache/cassandra/utils/SlabAllocator.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/utils/SlabAllocator.java b/src/java/org/apache/cassandra/utils/SlabAllocator.java
index 6ff66f8..edd6f86 100644
--- a/src/java/org/apache/cassandra/utils/SlabAllocator.java
+++ b/src/java/org/apache/cassandra/utils/SlabAllocator.java
@@ -48,7 +48,7 @@ public class SlabAllocator extends Allocator
     private final static int MAX_CLONED_SIZE = 128 * 1024; // bigger than this don't go in
the region
 
     private final AtomicReference<Region> currentRegion = new AtomicReference<Region>();
-    private volatile int regionCount = 0;
+    private final AtomicInteger regionCount = new AtomicInteger(0);
     private AtomicLong unslabbed = new AtomicLong(0);
 
     public ByteBuffer allocate(int size)
@@ -99,7 +99,7 @@ public class SlabAllocator extends Allocator
             {
                 // we won race - now we need to actually do the expensive allocation step
                 region.init();
-                regionCount++;
+                regionCount.incrementAndGet();
                 logger.trace("{} regions now allocated in {}", regionCount, this);
                 return region;
             }
@@ -113,7 +113,7 @@ public class SlabAllocator extends Allocator
      */
     public long getMinimumSize()
     {
-        return unslabbed.get() + (regionCount - 1) * (long)REGION_SIZE;
+        return unslabbed.get() + (regionCount.get() - 1) * (long)REGION_SIZE;
     }
 
     /**
@@ -121,7 +121,7 @@ public class SlabAllocator extends Allocator
      */
     public long getMaximumSize()
     {
-        return unslabbed.get() + regionCount * (long)REGION_SIZE;
+        return unslabbed.get() + regionCount.get() * (long)REGION_SIZE;
     }
 
     /**


Mime
View raw message