LLFIO v2.00
Loading...
Searching...
No Matches
llfio_v2_xxx::dynamic_thread_pool_group::work_item Class Referenceabstract

An individual item of work within the work group. More...

#include "dynamic_thread_pool_group.hpp"

Inheritance diagram for llfio_v2_xxx::dynamic_thread_pool_group::work_item:
llfio_v2_xxx::dynamic_thread_pool_group::io_aware_work_item

Public Member Functions

dynamic_thread_pool_groupparent () const noexcept
 Returns the parent work group between successful submission and just before group_complete().
 
virtual intptr_t next (deadline &d) noexcept=0
 
virtual result< void > operator() (intptr_t work) noexcept=0
 
virtual void group_complete (const result< void > &cancelled) noexcept
 

Protected Member Functions

constexpr bool _has_timer_set_relative () const noexcept
 
constexpr bool _has_timer_set_absolute () const noexcept
 
constexpr bool _has_timer_set () const noexcept
 
 work_item (const work_item &o)=delete
 
 work_item (work_item &&o) noexcept
 
work_itemoperator= (const work_item &)=delete
 
work_itemoperator= (work_item &&)=delete
 

Friends

class dynamic_thread_pool_group_impl
 

Detailed Description

An individual item of work within the work group.

Constructor & Destructor Documentation

◆ work_item() [1/2]

constexpr llfio_v2_xxx::dynamic_thread_pool_group::work_item::work_item ( )
inlineconstexprprotected
216{}

◆ work_item() [2/2]

llfio_v2_xxx::dynamic_thread_pool_group::work_item::work_item ( work_item &&  o)
inlineprotectednoexcept
219 : _parent(o._parent.load(std::memory_order_relaxed))
220 , _internalworkh(o._internalworkh)
221 , _internaltimerh(o._internaltimerh)
222 , _prev(o._prev)
223 , _next(o._next)
224 , _next_scheduled(o._next_scheduled)
225 , _nextwork(o._nextwork.load(std::memory_order_relaxed))
226 , _timepoint1(o._timepoint1)
227 , _timepoint2(o._timepoint2)
228 , _internalworkh_inuse(o._internalworkh_inuse)
229 {
230 assert(o._parent.load(std::memory_order_relaxed) == nullptr);
231 assert(o._internalworkh == nullptr);
232 assert(o._internaltimerh == nullptr);
233 if(o._parent.load(std::memory_order_relaxed) != nullptr || o._internalworkh != nullptr)
234 {
235 LLFIO_LOG_FATAL(this, "FATAL: dynamic_thread_pool_group::work_item was relocated in memory during use!");
236 abort();
237 }
238 o._prev = o._next = o._next_scheduled = nullptr;
239 o._nextwork.store(-1, std::memory_order_relaxed);
240 o._internalworkh_inuse = 0;
241 }

◆ ~work_item()

virtual llfio_v2_xxx::dynamic_thread_pool_group::work_item::~work_item ( )
inlinevirtual
247 {
248 assert(_nextwork.load(std::memory_order_relaxed) == -1);
249 if(_nextwork.load(std::memory_order_relaxed) != -1)
250 {
251 LLFIO_LOG_FATAL(this, "FATAL: dynamic_thread_pool_group::work_item destroyed before all work was done!");
252 abort();
253 }
254 assert(_internalworkh == nullptr);
255 assert(_internaltimerh == nullptr);
256 assert(_parent == nullptr);
257 if(_internalworkh != nullptr || _parent != nullptr)
258 {
259 LLFIO_LOG_FATAL(this, "FATAL: dynamic_thread_pool_group::work_item destroyed before group_complete() was executed!");
260 abort();
261 }
262 }

Member Function Documentation

◆ _has_timer_set()

constexpr bool llfio_v2_xxx::dynamic_thread_pool_group::work_item::_has_timer_set ( ) const
inlineconstexprprotectednoexcept
214{ return _has_timer_set_relative() || _has_timer_set_absolute(); }

◆ _has_timer_set_absolute()

constexpr bool llfio_v2_xxx::dynamic_thread_pool_group::work_item::_has_timer_set_absolute ( ) const
inlineconstexprprotectednoexcept
213{ return _timepoint2 != std::chrono::system_clock::time_point(); }

◆ _has_timer_set_relative()

constexpr bool llfio_v2_xxx::dynamic_thread_pool_group::work_item::_has_timer_set_relative ( ) const
inlineconstexprprotectednoexcept
212{ return _timepoint1 != std::chrono::steady_clock::time_point(); }

◆ group_complete()

virtual void llfio_v2_xxx::dynamic_thread_pool_group::work_item::group_complete ( const result< void > &  cancelled)
inlinevirtualnoexcept

Invoked by the i/o thread pool when all work in this thread pool group is complete.

cancelled indicates if this is an abnormal completion. If its error compares equal to errc::operation_cancelled, then stop() was called.

Just before this is called for all work items submitted, the group becomes reset to fresh, and parent() becomes null. You can resubmit this work item, but do not submit other work items until their group_complete() has been invoked.

Note that this function is called from multiple kernel threads.

dynamic_thread_pool_group::current_work_item() may have any value during this call.

324{ (void) cancelled; }

◆ next()

virtual intptr_t llfio_v2_xxx::dynamic_thread_pool_group::work_item::next ( deadline d)
pure virtualnoexcept

Invoked by the i/o thread pool to determine if this work item has more work to do.

Returns
If there is no work currently available to do, but there might be some later, you should return zero. You will be called again later after other work has been done. If you return -1, you are saying that no further work will be done, and the group need never call you again. If you have more work you want to do, return any other value.
Parameters
dOptional delay before the next item of work ought to be executed (return != 0), or next() ought to be called again to determine the next item (return == 0). On entry d is set to no delay, so if you don't modify it, the next item of work occurs as soon as possible.

Note that this function is called from multiple kernel threads. You must NOT do any significant work in this function. In particular do NOT call any dynamic thread pool group function, as you will experience deadlock.

dynamic_thread_pool_group::current_work_item() may have any value during this call.

◆ operator()()

virtual result< void > llfio_v2_xxx::dynamic_thread_pool_group::work_item::operator() ( intptr_t  work)
pure virtualnoexcept

Invoked by the i/o thread pool to perform the next item of work.

Returns
Any failure causes all remaining work in this group to be cancelled as soon as possible.
Parameters
workThe value returned by next().

Note that this function is called from multiple kernel threads, and may not be the kernel thread from which next() was called.

dynamic_thread_pool_group::current_work_item() will always be this during this call.

◆ parent()

dynamic_thread_pool_group * llfio_v2_xxx::dynamic_thread_pool_group::work_item::parent ( ) const
inlinenoexcept

Returns the parent work group between successful submission and just before group_complete().

265{ return reinterpret_cast<dynamic_thread_pool_group *>(_parent.load(std::memory_order_relaxed)); }

The documentation for this class was generated from the following file: