/** * Get latest data from producer. Run before a sequence of @see{read} * * @return true if there is new data available */ public boolean poll() { // Reading from commitPosition inserts a memory read barrier, making sure that this thread's caches are coherent readLimit = commitPosition.get(); if(readPosition < readLimit) { return true; } else { return false; } }
/** * Flushes read objects, making them available for writing. Call after @see{read} */ public void flush() { consumerPosition.set(readPosition); }
/** * Make all objects set using @see{next} since last commit visible to the consumer * */ public void commit() { // Set the commitPosition to writePosition. Writing to commitPosition inserts a memory write barrier commitPosition.set(writePosition); }
/** * Get latest data from producer. Run before a sequence of @see{read} * * @return true if there is new data available */ public boolean poll() { // Reading from commitPosition inserts a memory read barrier, making sure that this thread's caches are coherent readLimit = commitPosition.get(); if(readPosition < readLimit) { return true; } else { return false; } }
/** * Make all objects set using @see{next} since last commit visible to the consumer * */ public void commit() { // Set the commitPosition to writePosition. Writing to commitPosition inserts a memory write barrier commitPosition.set(writePosition); }
/** * Get a new object for writing, return null if there is no space in the buffer * * @return Object for writing */ public T next() { ++writePosition; if(writePosition >= cachedMaxWritePosition) { cachedMaxWritePosition = consumerPosition.get() + capacity; if(writePosition >= cachedMaxWritePosition) { --writePosition; return null; } } return getObject(writePosition); }
/** * Flushes read objects, making them available for writing. Call after @see{read} */ public void flush() { consumerPosition.set(readPosition); }
/** * Get a new object for writing, return null if there is no space in the buffer * * @return Object for writing */ public T next() { ++writePosition; if(writePosition >= cachedMaxWritePosition) { cachedMaxWritePosition = consumerPosition.get() + capacity; if(writePosition >= cachedMaxWritePosition) { --writePosition; return null; } } return getObject(writePosition); }