public RingBuffer < T > put ( T element ) throws InterruptedException { if ( element == null ) return this ; lock . lock ( ) ; try { while ( count == buf . length ) not_full . await ( ) ; buf [ wi ] = element ; if ( ++ wi == buf . length ) wi = 0 ; count ++ ; not_empty . signal ( ) ; return this ; } finally { lock . unlock ( ) ; } }
Tries to add a new element at the current write index and advances the write index . If the write index is at the same position as the read index this will block until the read index is advanced .