Donner SVG main
0.8.0 ยท 766e862a0.8.0 main
SVG editor and embeddable C⁠+⁠+⁠20 engine.
Loading...
Searching...
No Matches
donner::tasks::TaskRecord Class Reference

One spawned task: its closure, and what the thread that finishes it needs. More...

#include "donner/base/tasks/TaskRecord.h"

Inheritance diagram for donner::tasks::TaskRecord:
[legend]

Public Member Functions

 TaskRecord (const TaskRecord &)=delete
 TaskRecord (TaskRecord &&)=delete
TaskRecord & operator= (const TaskRecord &)=delete
TaskRecord & operator= (TaskRecord &&)=delete
template<typename F>
void setClosure (F &&work)
 Stores work as the record's closure.
void run ()
 Runs the closure, then destroys it. The record must hold one.
void discard ()
 Destroys the closure without running it. The record must hold one.
bool hasClosure () const
 Whether the record holds a closure.
void setScope (std::atomic< std::uint64_t > *scopeCounter, Parker<> *parker, const ScopeStop *stop)
 Records what the finisher of this task touches: its scope's counter and the parker the scope recorded; and the scope's stop request, which the thread that takes the task checks first.
void setAsyncScope (AsyncTaskScope *scope)
 Records the asynchronous scope to notify after returning this record.
AsyncTaskScope * asyncScope () const
std::atomic< std::uint64_t > * scopeCounter () const
 The scope counter set by setScope, or null.
Parker * parker () const
 The parker set by setScope, or null.
const ScopeStop * stop () const
 The scope's stop request set by setScope, or null.
TaskRecord * next () const
 The intrusive link, owned by whichever list holds the record.
void setNext (TaskRecord *next)
 Sets the intrusive link.
const void * pool () const
 The identity of the pool that allocated the record.
Public Member Functions inherited from donner::tasks::SchedulerWork
 SchedulerWork (Kind kind)

Static Public Attributes

static constexpr std::size_t kInlineBytes = 64
 Bytes of closure storage inside the record.
static constexpr std::size_t kInlineAlignment = alignof(std::max_align_t)
 Alignment of the inline closure storage.
template<typename F>
static constexpr bool kStoredInline
 Whether a closure of type F is stored inline rather than in a heap block.

Friends

template<typename>
class CreatorRecordPool
class RecordStore

Additional Inherited Members

Public Types inherited from donner::tasks::SchedulerWork
enum class  Kind {
  Record ,
  Resumption
}
Public Attributes inherited from donner::tasks::SchedulerWork
SchedulerWork * next = nullptr
const Kind kind

Detailed Description

One spawned task: its closure, and what the thread that finishes it needs.

Layout: an intrusive link and work kind, its allocating pool, completion and stop metadata, the closure's call function, and 64 bytes of inline closure storage. A closure that does not fit, or needs more than max_align_t alignment, is moved into a heap block that the record owns. The record is 128 bytes, two cache lines.

Records are recycled by their pool. While a record is free, everything after its intrusive link is poisoned in AddressSanitizer builds, so a thread that touches a record after returning it fails there.

Member Function Documentation

◆ setClosure()

template<typename F>
void donner::tasks::TaskRecord::setClosure ( F && work)
inline

Stores work as the record's closure.

The record must hold none.

Parameters
workCallable with no arguments.

◆ setScope()

void donner::tasks::TaskRecord::setScope ( std::atomic< std::uint64_t > * scopeCounter,
Parker<> * parker,
const ScopeStop * stop )
inline

Records what the finisher of this task touches: its scope's counter and the parker the scope recorded; and the scope's stop request, which the thread that takes the task checks first.

Parameters
scopeCounterThe scope's counter word.
parkerThe parker to change when the counter reaches zero.
stopThe scope's stop request, or null for a scope without one.

Member Data Documentation

◆ kStoredInline

template<typename F>
bool donner::tasks::TaskRecord::kStoredInline
staticconstexpr
Initial value:
=
sizeof(std::decay_t<F>) <= kInlineBytes && alignof(std::decay_t<F>) <= kInlineAlignment
static constexpr std::size_t kInlineAlignment
Alignment of the inline closure storage.
Definition TaskRecord.h:54
static constexpr std::size_t kInlineBytes
Bytes of closure storage inside the record.
Definition TaskRecord.h:51

Whether a closure of type F is stored inline rather than in a heap block.


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