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

The task records of one creator, a worker or an adoptable slot: at most maxTasksPerCreator live records, allocated by the creator alone. More...

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

Public Member Functions

 CreatorRecordPool (std::size_t maxLiveRecords)
 CreatorRecordPool (const CreatorRecordPool &)=delete
 CreatorRecordPool (CreatorRecordPool &&)=delete
CreatorRecordPool & operator= (const CreatorRecordPool &)=delete
CreatorRecordPool & operator= (CreatorRecordPool &&)=delete
 ~CreatorRecordPool ()
 Creator only, after every other thread has returned its records. Fails a release assertion if any record is still live.
TaskRecord * tryAllocate ()
 Allocates a record.
void releaseFromCreator (TaskRecord *record)
 Returns a record the creator ran itself. Creator only.
void returnFromOtherThread (TaskRecord *record)
 Returns a record that this thread ran.
std::size_t reclaimReturned ()
 Moves every returned record to the free list.
std::size_t liveCount () const
 Records allocated and not yet taken back. Creator only.
std::size_t createdCount () const
 Records created so far; never above maxLiveRecords. Creator only.
std::size_t maxLiveRecords () const
 The bound on live records.

Detailed Description

template<typename Hooks = NoRecordPoolHooks>
class donner::tasks::CreatorRecordPool< Hooks >

The task records of one creator, a worker or an adoptable slot: at most maxTasksPerCreator live records, allocated by the creator alone.

The creator allocates, and returns the records it ran itself, with no atomic operation. A record that another thread ran is returned by that thread onto the pool's return stack, a lock-free multi-producer stack with one consumer: each return links the record to the head it read and publishes it with a release compare-and-swap, and the creator takes the whole stack with one acquire exchange when its free list runs empty. Since nothing pops single entries, a head that is taken, reused and returned again cannot corrupt a return that read it earlier: the compare-and-swap succeeds only if that record is the head again, and the record then links to it, which is correct.

A record is counted live from allocation until the creator takes it back, so a returned record still counts until the creator's next take. When the free list and the return stack are empty and the bound is reached, tryAllocate returns null and the caller runs the task inline.

Template Parameters
HooksTest seam, see NoRecordPoolHooks.

Constructor & Destructor Documentation

◆ CreatorRecordPool()

template<typename Hooks = NoRecordPoolHooks>
donner::tasks::CreatorRecordPool< Hooks >::CreatorRecordPool ( std::size_t maxLiveRecords)
inlineexplicit
Parameters
maxLiveRecordsThe bound on live records, above zero.

Member Function Documentation

◆ reclaimReturned()

template<typename Hooks = NoRecordPoolHooks>
std::size_t donner::tasks::CreatorRecordPool< Hooks >::reclaimReturned ( )
inline

Moves every returned record to the free list.

Creator only.

Returns
The number of records taken back.

◆ returnFromOtherThread()

template<typename Hooks = NoRecordPoolHooks>
void donner::tasks::CreatorRecordPool< Hooks >::returnFromOtherThread ( TaskRecord * record)
inline

Returns a record that this thread ran.

Any thread but the creator. The calling thread must not touch the record afterwards.

Parameters
recordA record of this pool holding no closure.

◆ tryAllocate()

template<typename Hooks = NoRecordPoolHooks>
TaskRecord * donner::tasks::CreatorRecordPool< Hooks >::tryAllocate ( )
inlinenodiscard

Allocates a record.

Creator only. Takes back returned records first when the free list is empty.

Returns
The record, cleared and holding no closure; or null when the bound is reached, in which case the caller runs the task inline.

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