diff --git a/plugins/GSdx/boost_spsc_queue.hpp b/plugins/GSdx/boost_spsc_queue.hpp index c1104a5de7..cd595e95d9 100644 --- a/plugins/GSdx/boost_spsc_queue.hpp +++ b/plugins/GSdx/boost_spsc_queue.hpp @@ -44,6 +44,10 @@ // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +#include + +// I don't like it +using namespace std; template class ringbuffer_base @@ -54,6 +58,8 @@ class ringbuffer_base char padding1[padding_size]; /* force read_index and write_index to different cache lines */ atomic read_index_; + size_t pending_pop_read_index; + T *buffer; ringbuffer_base(ringbuffer_base const &) = delete; @@ -123,6 +129,21 @@ public: return true; } + T& front() + { + pending_pop_read_index = read_index_.load(memory_order_relaxed); // only written from pop thread + + return buffer[pending_pop_read_index]; + } + + void pop() + { + buffer[pending_pop_read_index].~T(); + + size_t next = next_index(pending_pop_read_index); + read_index_.store(next, memory_order_release); + } + template bool consume_one(Functor & f) { @@ -169,6 +190,17 @@ public: return write_index_.is_lock_free() && read_index_.is_lock_free(); } + size_t size() const + { + const size_t write_index = write_index_.load(memory_order_relaxed); + const size_t read_index = read_index_.load(memory_order_relaxed); + if (read_index > write_index) { + return (write_index + max_size) - read_index; + } else { + return write_index - read_index; + } + } + private: bool empty(size_t write_index, size_t read_index) {