@ Override public boolean checkRead ( ) { // Was the value prefetched already? If so, return. int h = queue . frontPos ( ) ; if ( h != r ) { return true ; } // There's no prefetched value, so let us prefetch more values. // Prefetching is to simply retrieve the // pointer from c in atomic fashion. If there are no // items to prefetch, set c to -1 (using compare-and-swap). if ( c . compareAndSet ( h , - 1 ) ) { // nothing to read, h == r must be the same } else { // something to have been written r = c . get ( ) ; } // If there are no elements prefetched, exit. // During pipe's lifetime r should never be NULL, however, // it can happen during pipe shutdown when items // are being deallocated. if ( h == r || r == - 1 ) { return false ; } // There was at least one value prefetched. return true ; }
Check whether item is available for reading .