-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
101 additions
and
16 deletions.
There are no files selected for viewing
10 changes: 8 additions & 2 deletions
10
client/src/main/java/org/infinispan/creson/AtomicBoolean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
client/src/main/java/org/infinispan/creson/AtomicReference.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.infinispan.creson; | ||
|
||
public class AtomicReference<T> { | ||
|
||
public String name; | ||
private T value; | ||
|
||
public AtomicReference(){} | ||
|
||
public AtomicReference(String name, T v){ | ||
this.name = name; | ||
this.value = v; | ||
} | ||
|
||
public T get(){ | ||
return value; | ||
} | ||
|
||
public void set(T v){ | ||
this.value = v; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
client/src/main/java/org/infinispan/creson/ScalableCyclicBarrier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package org.infinispan.creson; | ||
|
||
public class ScalableCyclicBarrier { | ||
|
||
private static final int SLEEP = 10; | ||
|
||
private final AtomicBoolean answers[][]; | ||
private final int parties, logParties; | ||
|
||
private AtomicCounter identity; | ||
private ThreadLocal<Integer> myIdentifier; | ||
|
||
public ScalableCyclicBarrier(final String name, final int parties){ | ||
this.parties = parties; | ||
this.logParties = (int)(Math.log(parties)/Math.log(2)); | ||
this.answers = new AtomicBoolean[parties][parties]; | ||
for(int p=0; p<parties; p++) { | ||
for(int i=0; i<logParties; i++){ | ||
this.answers[p][i] = new AtomicBoolean(name+"-"+p+"-"+i,false); | ||
} | ||
} | ||
this.identity = new AtomicCounter(name+"-identity",-1); | ||
this.myIdentifier = new ThreadLocal<>(); | ||
} | ||
|
||
public int await(){ | ||
if (this.myIdentifier.get()==null) this.myIdentifier.set(identity.increment()); | ||
int myId = this.myIdentifier.get(); | ||
|
||
int intended[] = new int[logParties]; | ||
int power = 1; | ||
for(int i=0; i<logParties; i++){ | ||
intended[i] = (power + myId) % parties; | ||
power = power * 2; | ||
} | ||
|
||
try{ | ||
for(int instance=0; instance<logParties; instance++) { | ||
while (answers[intended[instance]][instance].get()) {Thread.currentThread().sleep(SLEEP);} | ||
answers[intended[instance]][instance].set(true); | ||
while (!answers[myId][instance].get()) {Thread.currentThread().sleep(SLEEP);} | ||
answers[myId][instance].set(false); | ||
} | ||
} catch (InterruptedException e) { | ||
// ignore | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters