Support range-based 'for' loop for ParallelWork. (#1786)

This commit is contained in:
xiehan
2025-10-09 22:05:34 +08:00
committed by GitHub
parent 50d5717035
commit 649a65e983
3 changed files with 19 additions and 16 deletions

View File

@@ -93,18 +93,11 @@ SubTask *WFGraphTask::done()
WFGraphTask::~WFGraphTask()
{
SeriesWork *series;
size_t i;
if (this->parallel)
{
for (i = 0; i < this->parallel->size(); i++)
{
series = this->parallel->series_at(i);
for (SeriesWork *series : *this->parallel)
series->unset_last_task();
}
this->parallel->dismiss();
}
}

View File

@@ -245,18 +245,29 @@ public:
return NULL;
}
SeriesWork& operator[] (size_t index)
{
return *this->series_at(index);
}
SeriesWork& operator[] (size_t index) { return *this->all_series[index]; }
const SeriesWork& operator[] (size_t index) const
{
return *this->series_at(index);
return *this->all_series[index];
}
size_t size() const { return this->subtasks_nr; }
public:
SeriesWork *const *begin() { return this->all_series; }
SeriesWork *const *end() { return this->all_series + this->subtasks_nr; }
const SeriesWork *const *begin() const
{
return (const SeriesWork **)this->all_series;
}
const SeriesWork *const *end() const
{
return (const SeriesWork **)this->all_series + this->subtasks_nr;
}
public:
void set_callback(parallel_callback_t callback)
{

View File

@@ -26,11 +26,10 @@ void callback(const ParallelWork *pwork)
tutorial_series_context *ctx;
const void *body;
size_t size;
size_t i;
for (i = 0; i < pwork->size(); i++)
for (const SeriesWork *series : *pwork)
{
ctx = (tutorial_series_context *)pwork->series_at(i)->get_context();
ctx = (tutorial_series_context *)series->get_context();
printf("%s\n", ctx->url.c_str());
if (ctx->state == WFT_STATE_SUCCESS)
{