[buffer] add method to read last image
This commit is contained in:
parent
bc09438f2a
commit
506bb98879
@ -46,7 +46,7 @@ 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;
|
||||
//std::cerr << "load: " << bufferLoad() << "\t pressure: " << bufferPreassure() << std::endl;
|
||||
}
|
||||
|
||||
bool ImageBuffer::bufferNotEmpty() {
|
||||
@ -69,3 +69,19 @@ bool ImageBuffer::pop(MyImage &img) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool ImageBuffer::readLast(MyImage &img) {
|
||||
bool ret = false;
|
||||
mutex.lock();
|
||||
if (load > 0) {
|
||||
size_t idx;
|
||||
if (current_write_index != 0) {
|
||||
idx = static_cast<size_t>(current_write_index) - 1;
|
||||
} else {
|
||||
idx = buffer.capacity() -1;
|
||||
}
|
||||
img = buffer[idx];
|
||||
ret = true;
|
||||
}
|
||||
mutex.unlock();
|
||||
return ret;
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ public:
|
||||
void resize(size_t new_size);
|
||||
void push(const MyImage &img);
|
||||
bool pop(MyImage &img);
|
||||
bool readLast(MyImage &img);
|
||||
size_t capacity();
|
||||
double bufferPreassure();
|
||||
int64_t bufferLoad();
|
||||
|
Loading…
Reference in New Issue
Block a user