[buffer] fix read index
This commit is contained in:
parent
d336000553
commit
f68dc517ae
@ -33,7 +33,7 @@ void ImageBuffer::resize(size_t new_size) {
|
||||
buffer_size = new_size;
|
||||
buffer.clear();
|
||||
buffer.resize(new_size);
|
||||
current_read_index = -1;
|
||||
current_read_index = 0;
|
||||
current_write_index = -1;
|
||||
load = 0;
|
||||
mutex.unlock();
|
||||
@ -46,7 +46,6 @@ void ImageBuffer::push(const MyImage &img) {
|
||||
if (load < static_cast<int64_t>(buffer.capacity()))
|
||||
load += 1;
|
||||
mutex.unlock();
|
||||
//std::cerr << "load: " << bufferLoad() << "\t pressure: " << bufferPreassure() << std::endl;
|
||||
}
|
||||
|
||||
bool ImageBuffer::bufferNotEmpty() {
|
||||
@ -61,9 +60,11 @@ bool ImageBuffer::pop(MyImage &img) {
|
||||
bool ret = false;
|
||||
mutex.lock();
|
||||
if (load > 0) {
|
||||
std::cerr << "Buffer.pop, load: " << load << " read_idx: " << current_read_index << " write_idx: " << current_write_index << std::endl;
|
||||
img = buffer[static_cast<size_t>(current_read_index)];
|
||||
static_cast<size_t>(current_read_index) < (buffer.capacity() - 1) ? current_read_index += 1 : current_read_index = 0;
|
||||
load -= 1;
|
||||
ret = true;
|
||||
}
|
||||
mutex.unlock();
|
||||
return ret;
|
||||
|
@ -24,8 +24,6 @@ public:
|
||||
bool bufferNotEmpty();
|
||||
|
||||
private:
|
||||
// QWaitCondition bufferNotEmpty; // signals that the consumer can get data
|
||||
// QWaitCondition bufferNotFull; // signals that the producer can store data
|
||||
QMutex mutex;
|
||||
int numUsedBytes = 0;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user