int dequeue()

in src/cubeb_ringbuffer.h [151:178]


  int dequeue(T * elements, int count)
  {
#ifndef NDEBUG
    assert_correct_thread(consumer_id);
#endif

    int rd_idx = read_index_.load(std::memory_order_relaxed);
    int wr_idx = write_index_.load(std::memory_order_acquire);

    if (empty_internal(rd_idx, wr_idx)) {
      return 0;
    }

    int to_read = std::min(available_read_internal(rd_idx, wr_idx), count);

    int first_part = std::min(storage_capacity() - rd_idx, to_read);
    int second_part = to_read - first_part;

    if (elements) {
      Copy(elements, data_.get() + rd_idx, first_part);
      Copy(elements + first_part, data_.get(), second_part);
    }

    read_index_.store(increment_index(rd_idx, to_read),
                      std::memory_order_release);

    return to_read;
  }