ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject [16/16] ignite git commit: Fixed distance between stripes.
Date Mon, 11 Jan 2016 15:34:49 GMT
Fixed distance between stripes.


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

Branch: refs/heads/ignite-2316
Commit: 17b3a9f691a6907c5ffbfbce2e3bd58ca8f4d0a9
Parents: 13b4d37
Author: vozerov-gridgain <vozerov@gridgain.com>
Authored: Mon Jan 11 18:35:35 2016 +0300
Committer: vozerov-gridgain <vozerov@gridgain.com>
Committed: Mon Jan 11 18:35:35 2016 +0300

----------------------------------------------------------------------
 .../internal/util/GridStripedSpinBusyLock.java    | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/17b3a9f6/modules/core/src/main/java/org/apache/ignite/internal/util/GridStripedSpinBusyLock.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/GridStripedSpinBusyLock.java
b/modules/core/src/main/java/org/apache/ignite/internal/util/GridStripedSpinBusyLock.java
index 064e044..f665bd8 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/GridStripedSpinBusyLock.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/GridStripedSpinBusyLock.java
@@ -67,7 +67,7 @@ public class GridStripedSpinBusyLock {
         this.stripeCnt = stripeCnt;
 
         // Each state must be located 64 bytes from the other to avoid false sharing.
-        states = new AtomicIntegerArray(stripeCnt * 16);
+        states = new AtomicIntegerArray(adjusted(stripeCnt));
     }
 
     /**
@@ -100,7 +100,7 @@ public class GridStripedSpinBusyLock {
     public void block() {
         // 1. CAS-loop to set a writer bit.
         for (int i = 0; i < stripeCnt; i++) {
-            int idx = i << 2;
+            int idx = adjusted(i);
 
             while (true) {
                 int oldVal = states.get(idx);
@@ -114,7 +114,7 @@ public class GridStripedSpinBusyLock {
         boolean interrupt = false;
 
         for (int i = 0; i < stripeCnt; i++) {
-            int idx = i << 2;
+            int idx = adjusted(i);
 
             while (states.get(idx) != WRITER_MASK) {
                 try {
@@ -136,6 +136,16 @@ public class GridStripedSpinBusyLock {
      * @return Index for the given thread.
      */
     private int index() {
-        return (THREAD_IDX.get() % stripeCnt) << 2;
+        return adjusted(THREAD_IDX.get() % stripeCnt);
+    }
+
+    /**
+     * Gets value adjusted for striping.
+     *
+     * @param val Value.
+     * @return Value.
+     */
+    private static int adjusted(int val) {
+        return val << 4;
     }
 }


Mime
View raw message