@@ -0,0 +1,1383 @@
+package jocket.futex;%0A%0Aimport java.lang.reflect.Field;%0Aimport java.nio.MappedByteBuffer;%0A%0Aimport sun.misc.Unsafe;%0A%0Apublic class Futex %7B%0A%0A  private static boolean libAvailable;%0A%0A  private final long addr;%0A%0A  private static final Unsafe UNSAFE = initUnsafe();%0A%0A  static %7B%0A    // TODO: load from classpath%0A    try %7B%0A      System.loadLibrary(%22JocketFutex%22);%0A      libAvailable = true;%0A    %7D%0A    catch (UnsatisfiedLinkError e) %7B%0A      libAvailable = false;%0A    %7D%0A  %7D%0A%0A  public static boolean isAvailable() %7B%0A    return libAvailable;%0A  %7D%0A%0A  public Futex(MappedByteBuffer b, int pos) %7B%0A    this.addr = computeAddress(b, pos);%0A  %7D%0A%0A  private static Unsafe initUnsafe() %7B%0A    try %7B%0A      Field f = Unsafe.class.getDeclaredField(%22theUnsafe%22);%0A      f.setAccessible(true);%0A      Unsafe unsafe = (Unsafe) f.get(null);%0A      return unsafe;%0A    %7D%0A    catch (Exception ex) %7B%0A      throw new RuntimeException(ex);%0A    %7D%0A  %7D%0A%0A  private static long computeAddress(MappedByteBuffer b, int pos) %7B%0A    try %7B%0A      return getAddress(b) + pos / UNSAFE.addressSize();%0A    %7D%0A    catch (Exception e) %7B%0A      throw new RuntimeException(e);%0A    %7D%0A  %7D%0A%0A  private static native long getAddress(MappedByteBuffer b);%0A%0A  public void signal() %7B%0A    signal0(addr);%0A  %7D%0A%0A  public void await() %7B%0A    await0(addr);%0A  %7D%0A%0A  private static native void signal0(long addr);%0A%0A  private static native void await0(long addr);%0A%0A%7D%0A

Add futex abstraction