public int drainTo ( T [ ] c ) { int num = Math . min ( count , c . length ) ; // count may increase in the mean time, but that's ok if ( num == 0 ) return num ; int read_index = ri ; // no lock as we're the only reader for ( int i = 0 ; i < num ; i ++ ) { int real_index = realIndex ( read_index + i ) ; c [ i ] = ( buf [ real_index ] ) ; buf [ real_index ] = null ; } publishReadIndex ( num ) ; return num ; }
Removes messages and adds them to c .