Do not inherit WorkerDisposableTask from WorkerTask

WorkerDisposableTask is intended to be passed using auto_ptr, to
make it plain that the ownership is moved. If it's inherited from
WorkerTask it can be passed as a WorkerTask, which is confusing as
it in that case will not be disposed of.
This commit is contained in:
Johan Wikman 2017-05-04 14:06:44 +03:00
parent 5de5609692
commit 6c4a4a3ee0
2 changed files with 23 additions and 1 deletions

View File

@ -47,11 +47,29 @@ public:
* When the task has been executed, the instance will automatically be
* deleted.
*/
class WorkerDisposableTask : public WorkerTask
class WorkerDisposableTask
{
protected:
/**
* Constructor
*/
WorkerDisposableTask();
/**
* Destructor
*/
virtual ~WorkerDisposableTask();
/**
* @brief Called in the context of a specific worker.
*
* @param worker The worker in whose context `execute` is called.
*
* @attention As the function is called by a worker, the body of `execute`
* should execute quickly and not perform any blocking operations.
*/
virtual void execute(Worker& worker) = 0;
private:
friend class Worker;

View File

@ -33,6 +33,10 @@ WorkerDisposableTask::WorkerDisposableTask()
{
}
WorkerDisposableTask::~WorkerDisposableTask()
{
}
void WorkerDisposableTask::inc_ref()
{
atomic_add(&m_count, 1);