Add SeriesWork::get_specific(), get_in_parallel for tracing.

This commit is contained in:
Xie Han
2023-04-04 20:47:16 +08:00
parent 8c210609ad
commit e103f8521e
3 changed files with 13 additions and 8 deletions

View File

@@ -828,7 +828,7 @@ public:
callback(std::move(cb))
{
this->first = first;
this->set_in_parallel();
this->set_in_parallel(this);
this->user_data = NULL;
}

View File

@@ -31,7 +31,6 @@ SeriesWork::SeriesWork(SubTask *first, series_callback_t&& cb) :
this->queue_size = sizeof this->buf / sizeof *this->buf;
this->front = 0;
this->back = 0;
this->in_parallel = false;
this->canceled = false;
this->finished = false;
assert(!series_of(first));
@@ -39,6 +38,7 @@ SeriesWork::SeriesWork(SubTask *first, series_callback_t&& cb) :
this->first = first;
this->last = NULL;
this->context = NULL;
this->in_parallel = NULL;
}
SeriesWork::~SeriesWork()
@@ -181,7 +181,7 @@ ParallelWork::ParallelWork(SeriesWork *const all_series[], size_t n,
for (i = 0; i < n; i++)
{
assert(!all_series[i]->in_parallel);
all_series[i]->in_parallel = true;
all_series[i]->in_parallel = this;
this->all_series[i] = all_series[i];
this->subtasks[i] = all_series[i]->first;
}
@@ -211,7 +211,7 @@ void ParallelWork::add_series(SeriesWork *series)
this->expand_buf();
assert(!series->in_parallel);
series->in_parallel = true;
series->in_parallel = this;
this->all_series[this->subtasks_nr] = series;
this->subtasks[this->subtasks_nr] = series->first;
this->subtasks_nr++;
@@ -239,7 +239,7 @@ ParallelWork::~ParallelWork()
for (i = 0; i < this->subtasks_nr; i++)
{
this->all_series[i]->in_parallel = false;
this->all_series[i]->in_parallel = NULL;
this->all_series[i]->dismiss_recursive();
}

View File

@@ -108,7 +108,10 @@ public:
}
public:
/* The next 3 functions are intended for task implementations only. */
virtual void *get_specific(const char *key) { return NULL; }
public:
/* The following functions are intended for task implementations only. */
SubTask *pop();
void set_last_task(SubTask *last)
@@ -119,10 +122,12 @@ public:
void unset_last_task() { this->last = NULL; }
const ParallelTask *get_in_parallel() const { return this->in_parallel; }
protected:
SubTask *get_last_task() const { return this->last; }
void set_in_parallel() { this->in_parallel = true; }
void set_in_parallel(const ParallelTask *task) { this->in_parallel = task; }
void dismiss_recursive();
@@ -142,9 +147,9 @@ private:
int queue_size;
int front;
int back;
bool in_parallel;
bool canceled;
bool finished;
const ParallelTask *in_parallel;
std::mutex mutex;
protected: