Implement write index as well

This commit is contained in:
2020-05-27 15:51:59 +02:00
parent 67d27c4618
commit 7613ce40dc
2 changed files with 8 additions and 2 deletions
+7 -2
View File
@@ -17,6 +17,7 @@ ImageAssembler::ImageAssembler(const size_t n_modules) :
}
read_slot_id_ = 0;
write_slot_id_ = 0;
}
ImageAssembler::~ImageAssembler()
@@ -27,7 +28,11 @@ ImageAssembler::~ImageAssembler()
int ImageAssembler::get_free_slot()
{
if (buffer_status_[write_slot_id_] > 0) {
return write_slot_id_;
}
return -1;
}
void ImageAssembler::process(
@@ -71,8 +76,8 @@ void ImageAssembler::process(
// 1 because fetch is done before subtraction.
if (previous_status == 1) {
write_slot_id_++;
read_slot_id_ %= IA_N_SLOTS;
auto next_write_slot_id = (int)((write_slot_id_+1) % IA_N_SLOTS);
write_slot_id_ = next_write_slot_id;
}
}
+1
View File
@@ -16,6 +16,7 @@ class ImageAssembler {
std::atomic_int* buffer_status_;
int read_slot_id_;
std::atomic_int write_slot_id_;
public:
ImageAssembler(const size_t n_modules);