class LatchMap {

    Latch takeOrAwaitLatch( long identifier )
    {
        int index = index( identifier );
        Latch latch = getLatch( index );
        while ( latch == null )
        {
            latch = new Latch();
            if ( compareAndSetLatch( index, null, latch ) )
            {
                latch.latchMap = this;
                latch.index = index;
                return latch;
            }
            latch = getLatch( index );
        }
        latch.await();
        return null;
    }

      LatchMap();

}