Skip to content

Commit

Permalink
QUEUE-6 introduced MappedNativeBytes into SingleChronicleQueue
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Austin committed Feb 19, 2015
1 parent 0d2a9fa commit b8b377d
Show file tree
Hide file tree
Showing 4 changed files with 194 additions and 153 deletions.
Expand Up @@ -55,8 +55,12 @@ public class SingleChronicleQueue implements ChronicleQueue, DirectChronicleQueu

public SingleChronicleQueue(String filename, long blockSize) throws IOException {
file = new MappedFile(filename, blockSize);

final ChronicleUnsafe chronicleUnsafe = new ChronicleUnsafe(file, blockSize);
MappedNativeBytes mappedNativeBytes = new MappedNativeBytes(chronicleUnsafe);

headerMemory = file.acquire(0);
bytes = headerMemory.bytes();
bytes = mappedNativeBytes;
wire = new ChronicleWire(new BinaryWire(bytes));
initialiseHeader();
}
Expand Down
Expand Up @@ -35,10 +35,22 @@ public class ChronicleUnsafe {
private final long mask;
private long last = -1;

public ChronicleUnsafe(MappedFile mappedFile, long shift) {

/**
* @param mappedFile
* @param blockSize this must be a power of 2
*/
public ChronicleUnsafe(MappedFile mappedFile, long blockSize) {

if (((blockSize & -blockSize) != blockSize))
throw new IllegalStateException("the block size has to be a power of 2");

this.mappedFile = mappedFile;
this.chunkSize = mappedFile.blockSize();

long shift = (int) (Math.log(blockSize) / Math.log(2));


mask = ~((1L << shift) - 1L);

/* System.out.println(Indexer.IndexOffset.toBinaryString(i));
Expand Down Expand Up @@ -206,7 +218,7 @@ public void putInt(long address, int v) {
}

public void putOrderedInt(Object o, long address, int v) {
UNSAFE.putOrderedInt(0, toAddress(address), v);
UNSAFE.putOrderedInt(o, toAddress(address), v);
}

public boolean compareAndSwapInt(Object o, long address, int expected, int v) {
Expand Down

0 comments on commit b8b377d

Please sign in to comment.