public SynchronizationPoint < NoException > startWriteAsync ( boolean returnNullIfReady ) { SynchronizationPoint < NoException > sp ; synchronized ( this ) { // if nobody is using the resource, we can start writing if ( readers == 0 && ! writer ) { writer = true ; return returnNullIfReady ? null : new SynchronizationPoint <> ( true ) ; } // someone is doing something, we need to block sp = new SynchronizationPoint < NoException > ( ) ; if ( writersWaiting == null ) writersWaiting = new LinkedList <> ( ) ; writersWaiting . add ( sp ) ; } return sp ; }
To call when a thread wants to enter write mode . If write can start immediately this method returns null . If the lock point is used in read mode this method will return a SynchronizationPoint unblocked when write can start .