-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTaskSet.h
More file actions
76 lines (65 loc) · 2.3 KB
/
TaskSet.h
File metadata and controls
76 lines (65 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
///////////////////////////////////////////////////////////////////////////////
// FILE: TaskSet.h
// PROJECT: Micro-Manager
// SUBSYSTEM: MMCore
//-----------------------------------------------------------------------------
// DESCRIPTION: Base class for grouping tasks for one logical operation.
//
// AUTHOR: Tomas Hanak, tomas.hanak@teledyne.com, 03/03/2021
// Andrej Bencur, andrej.bencur@teledyne.com, 03/03/2021
//
// COPYRIGHT: Teledyne Digital Imaging US, Inc., 2021
//
// LICENSE: This file is distributed under the "Lesser GPL" (LGPL) license.
// License text is included with the source distribution.
//
// This file is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES.
#pragma once
#include "Semaphore.h"
#include "Task.h"
#include "ThreadPool.h"
#include <memory>
#include <vector>
namespace mmcore {
namespace internal {
class TaskSet
{
public:
explicit TaskSet(std::shared_ptr<ThreadPool> pool);
virtual ~TaskSet();
TaskSet(const TaskSet&) = delete;
TaskSet& operator=(const TaskSet&) = delete;
size_t GetUsedTaskCount() const;
virtual void Execute();
virtual void Wait();
protected:
template<class T,
// Private param to enforce the type T derives from Task class
typename std::enable_if<std::is_base_of<Task, T>::value, int>::type = 0>
void CreateTasks()
{
const size_t taskCount = pool_->GetSize();
tasks_.reserve(taskCount);
for (size_t n = 0; n < taskCount; ++n)
{
Task* task = new(std::nothrow) T(semaphore_, n, taskCount);
if (!task)
continue;
tasks_.push_back(task);
}
usedTaskCount_ = tasks_.size();
}
protected:
const std::shared_ptr<ThreadPool> pool_;
const std::shared_ptr<Semaphore> semaphore_;
std::vector<Task*> tasks_{};
size_t usedTaskCount_{ 0 };
};
} // namespace internal
} // namespace mmcore