/** * Release the latch, thereby unblocking all current and future calls to {@link #await()}. */ public void release() { // Once the release sentinel is on the stack, it can never (observably) leave. // Waiters might accidentally remove the released sentinel from the stack for brief periods of time, but then // they are required to fix the situation and put it back. // Atomically swapping the release sentinel onto the stack will give us back all the waiters, if any. Node waiters = (Node) UnsafeUtil.getAndSetObject( this, stackOffset, released ); if ( waiters == null ) { // There are no waiters to unpark, so don't bother. return; } unparkSuccessor( waiters ); }
state = (Node) UnsafeUtil.getAndSetObject( this, stackOffset, waiter ); if ( state == released ) Node others = (Node) UnsafeUtil.getAndSetObject( this, stackOffset, released );
@Test void getAndSetObjectField() { Obj obj = new Obj(); long objectOffset = getFieldOffset( Obj.class, "object" ); assertThat( getAndSetObject( obj, objectOffset, obj ), is( nullValue() ) ); assertThat( getAndSetObject( obj, objectOffset, null ), sameInstance( obj ) ); assertThat( obj, is( new Obj() ) ); }
/** * Release the latch, thereby unblocking all current and future calls to {@link #await()}. */ public void release() { // Once the release sentinel is on the stack, it can never (observably) leave. // Waiters might accidentally remove the released sentinel from the stack for brief periods of time, but then // they are required to fix the situation and put it back. // Atomically swapping the release sentinel onto the stack will give us back all the waiters, if any. Node waiters = (Node) UnsafeUtil.getAndSetObject( this, stackOffset, released ); if ( waiters == null ) { // There are no waiters to unpark, so don't bother. return; } unparkSuccessor( waiters ); }
/** * Release the latch, thereby unblocking all current and future calls to {@link #await()}. */ public void release() { // Once the release sentinel is on the stack, it can never (observably) leave. // Waiters might accidentally remove the released sentinel from the stack for brief periods of time, but then // they are required to fix the situation and put it back. // Atomically swapping the release sentinel onto the stack will give us back all the waiters, if any. Node waiters = (Node) UnsafeUtil.getAndSetObject( this, stackOffset, released ); if ( waiters == null ) { // There are no waiters to unpark, so don't bother. return; } unparkSuccessor( waiters ); }
state = (Node) UnsafeUtil.getAndSetObject( this, stackOffset, waiter ); if ( state == released ) Node others = (Node) UnsafeUtil.getAndSetObject( this, stackOffset, released );
state = (Node) UnsafeUtil.getAndSetObject( this, stackOffset, waiter ); if ( state == released ) Node others = (Node) UnsafeUtil.getAndSetObject( this, stackOffset, released );