mirror of
https://github.com/sogou/workflow.git
synced 2026-10-21 14:52:26 +08:00
94 lines
1.7 KiB
C++
94 lines
1.7 KiB
C++
/*
|
|
Copyright (c) 2019 Sogou, Inc.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
|
|
Author: Xie Han (xiehan@sogou-inc.com)
|
|
*/
|
|
|
|
#ifndef _SUBTASK_H_
|
|
#define _SUBTASK_H_
|
|
|
|
#include <stddef.h>
|
|
|
|
class ParallelTask;
|
|
|
|
class SubTask
|
|
{
|
|
public:
|
|
virtual void dispatch() = 0;
|
|
|
|
private:
|
|
virtual SubTask *done() = 0;
|
|
|
|
protected:
|
|
void subtask_done();
|
|
|
|
public:
|
|
ParallelTask *get_parent_task() const { return this->parent; }
|
|
void *get_pointer() const { return this->pointer; }
|
|
void set_pointer(void *pointer) { this->pointer = pointer; }
|
|
|
|
private:
|
|
ParallelTask *parent;
|
|
SubTask **entry;
|
|
void *pointer;
|
|
|
|
public:
|
|
SubTask()
|
|
{
|
|
this->parent = NULL;
|
|
this->entry = NULL;
|
|
this->pointer = NULL;
|
|
}
|
|
|
|
virtual ~SubTask() { }
|
|
friend class ParallelTask;
|
|
};
|
|
|
|
class ParallelTask : public SubTask
|
|
{
|
|
public:
|
|
ParallelTask(SubTask **subtasks, size_t n)
|
|
{
|
|
this->subtasks = subtasks;
|
|
this->subtasks_nr = n;
|
|
}
|
|
|
|
SubTask **get_subtasks(size_t *n) const
|
|
{
|
|
*n = this->subtasks_nr;
|
|
return this->subtasks;
|
|
}
|
|
|
|
void set_subtasks(SubTask **subtasks, size_t n)
|
|
{
|
|
this->subtasks = subtasks;
|
|
this->subtasks_nr = n;
|
|
}
|
|
|
|
public:
|
|
virtual void dispatch();
|
|
|
|
protected:
|
|
SubTask **subtasks;
|
|
size_t subtasks_nr;
|
|
|
|
private:
|
|
size_t nleft;
|
|
friend class SubTask;
|
|
};
|
|
|
|
#endif
|
|
|