Taskflow  3.2.0-Master-Branch
Loading...
Searching...
No Matches
worker.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "declarations.hpp"
4#include "tsq.hpp"
5#include "notifier.hpp"
6
12namespace tf {
13
14// ----------------------------------------------------------------------------
15// Class Definition: Worker
16// ----------------------------------------------------------------------------
17
21class Worker {
22
23 friend class Executor;
24 friend class WorkerView;
25
26 private:
27
28 size_t _id;
29 size_t _vtm;
30 Executor* _executor;
31 Notifier::Waiter* _waiter;
33 TaskQueue<Node*> _wsq;
34};
35
36// ----------------------------------------------------------------------------
37// Class Definition: PerThreadWorker
38// ----------------------------------------------------------------------------
39
43//struct PerThreadWorker {
44//
45// Worker* worker;
46//
47// PerThreadWorker() : worker {nullptr} {}
48//
49// PerThreadWorker(const PerThreadWorker&) = delete;
50// PerThreadWorker(PerThreadWorker&&) = delete;
51//
52// PerThreadWorker& operator = (const PerThreadWorker&) = delete;
53// PerThreadWorker& operator = (PerThreadWorker&&) = delete;
54//};
55
59//inline PerThreadWorker& this_worker() {
60// thread_local PerThreadWorker worker;
61// return worker;
62//}
63
64// ----------------------------------------------------------------------------
65// Class Definition: WorkerView
66// ----------------------------------------------------------------------------
67
79
80 friend class Executor;
81
82 public:
83
91 size_t id() const;
92
97 size_t queue_size() const;
98
102 size_t queue_capacity() const;
103
104 private:
105
106 WorkerView(const Worker&);
107 WorkerView(const WorkerView&) = default;
108
109 const Worker& _worker;
110
111};
112
113// Constructor
114inline WorkerView::WorkerView(const Worker& w) : _worker{w} {
115}
116
117// function: id
118inline size_t WorkerView::id() const {
119 return _worker._id;
120}
121
122// Function: queue_size
123inline size_t WorkerView::queue_size() const {
124 return _worker._wsq.size();
125}
126
127// Function: queue_capacity
128inline size_t WorkerView::queue_capacity() const {
129 return static_cast<size_t>(_worker._wsq.capacity());
130}
131
132
133} // end of namespact tf -----------------------------------------------------
134
135
class to create an executor for running a taskflow graph
Definition executor.hpp:50
class to create an immutable view of a worker in an executor
Definition worker.hpp:78
size_t id() const
queries the worker id associated with the executor
Definition worker.hpp:118
size_t queue_capacity() const
queries the current capacity of the queue
Definition worker.hpp:128
size_t queue_size() const
queries the size of the queue (i.e., number of pending tasks to run) associated with the worker
Definition worker.hpp:123
taskflow namespace
Definition small_vector.hpp:27