Skip to content

Commit

Permalink
parallelize detection of material value
Browse files Browse the repository at this point in the history
  • Loading branch information
jw098 committed Jul 12, 2024
1 parent 3363a43 commit 60e1c4d
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,16 @@ std::vector<int8_t> ItemPrinterMaterialDetector::find_material_value_row_index(
VideoSnapshot snapshot = console.video().snapshot();
int8_t total_rows = 10;
std::vector<int8_t> row_indexes;
SpinLock lock;
std::vector<std::unique_ptr<AsyncTask>> tasks(total_rows);
for (int8_t row_index = 0; row_index < total_rows; row_index++){
int16_t value = read_number(console, dispatcher, snapshot, m_box_mat_value[row_index]);
if (value == material_value){
row_indexes.push_back(row_index);
}
tasks[row_index] = dispatcher.dispatch([&, row_index]{
int16_t value = read_number(console, dispatcher, snapshot, m_box_mat_value[row_index]);
if (value == material_value){
WriteSpinLock lg(lock);
row_indexes.push_back(row_index);
}
});
}

return row_indexes;
Expand Down

0 comments on commit 60e1c4d

Please sign in to comment.