Donner SVG main
0.8.0 ยท 766e862a0.8.0 main
SVG editor and embeddable C⁠+⁠+⁠20 engine.
Loading...
Searching...
No Matches
TaskScheduler.h File Reference

The task scheduler: worker threads, their deques, the global queue for threads that are not workers, and the sleep and publish protocol that keeps queued work from waiting on a sleeping pool. More...

#include <atomic>
#include <cstddef>
#include <cstdint>
#include <memory>
#include <mutex>
#include <optional>
#include <ostream>
#include <utility>
#include <vector>
#include "donner/base/Utils.h"
#include "donner/base/tasks/CoroutineFramePool.h"
#include "donner/base/tasks/FalseSharing.h"
#include "donner/base/tasks/Parker.h"
#include "donner/base/tasks/ParkerPool.h"
#include "donner/base/tasks/SchedulerWork.h"
#include "donner/base/tasks/ScopeStop.h"
#include "donner/base/tasks/TaskRecord.h"
#include "donner/base/tasks/WorkStealingDeque.h"
#include "donner/base/tasks/WorkerPolicy.h"
#include "donner/base/tasks/WorkerStack.h"
Include dependency graph for TaskScheduler.h:
This graph shows which files directly or indirectly include this file:

Classes

struct  donner::tasks::TaskSchedulerOptions
 Options for a TaskScheduler. More...
class  donner::tasks::SchedulerTestHooks
 Test seam: called at each SchedulerStep with the index of the worker the step concerns. More...
class  donner::tasks::AdoptedThread
 A thread-affine claim on one scheduler slot. Destroy it after its synchronous scopes. More...
class  donner::tasks::TaskScheduler
 A work-stealing task scheduler. More...
struct  donner::tasks::detail::ParallelForAccess
 Internal access to the optional loop instrumentation. More...
class  donner::tasks::ScheduleAwaitable
 Stores its queue entry in the suspended caller's frame. More...

Namespaces

namespace  donner
 Top-level Donner namespace, which is split into different sub-namespaces such as donner::svg and donner::css.

Enumerations

enum class  donner::tasks::WorkerState : std::uint8_t {
  Awake ,
  AsleepShallow ,
  AsleepDeep ,
  AwakeReserved
}
 A worker's state word. More...
enum class  donner::tasks::SchedulerStep : std::uint8_t {
  AfterDrain ,
  AfterWaitingBit ,
  AfterSleeperDecrement ,
  BeforeSleeperWaits ,
  BeforeSelfWakeSwap ,
  BeforeHandOff ,
  AfterPublishPush ,
  BetweenWakeSwapAndParkerChange ,
  AfterStopFlagSet ,
  ScopeWaiterBeforePrepareWait ,
  ScopeWaiterBeforeWait ,
  ResumptionPublished ,
  AsyncJoinBeforeRegister ,
  AsyncJoinRegistered ,
  AsyncJoinFinisherAfterDecrement ,
  AsyncJoinBeforeEnqueue ,
  ScopeFinisherAfterDecrement ,
  ParallelForBeforeClaim ,
  ParallelForAfterClaim ,
  AfterSearchStart ,
  WorkerBeforeStartupBarrier ,
  BeforeSearchStart ,
  AfterEmptySearch ,
  AfterAdoptedPush ,
  BeforeAdoptedStealClaim
}
 A point in the sleep, publish and shutdown protocols where a test can hold or delay a thread. More...

Functions

constexpr bool donner::tasks::IsWorkerAwake (WorkerState state)
 Whether a worker in this state counts toward the scheduler's awake total.
std::ostream & donner::tasks::operator<< (std::ostream &os, WorkerState state)
 Ostream output operator for WorkerState, for test diagnostics.
std::ostream & donner::tasks::operator<< (std::ostream &os, SchedulerStep step)
 Ostream output operator for SchedulerStep, for test diagnostics.

Detailed Description

The task scheduler: worker threads, their deques, the global queue for threads that are not workers, and the sleep and publish protocol that keeps queued work from waiting on a sleeping pool.

Enumeration Type Documentation

◆ SchedulerStep

enum class donner::tasks::SchedulerStep : std::uint8_t
strong

A point in the sleep, publish and shutdown protocols where a test can hold or delay a thread.

Enumerator
AfterDrain 

A sleeper drained its deque (step 1), before its waiting bit.

AfterWaitingBit 

A sleeper set its waiting bit (step 2), before it stores asleep.

AfterSleeperDecrement 

A sleeper stored asleep and decremented (step 3), before its re-check.

BeforeSleeperWaits 

A sleeper's re-check found nothing (step 4), before its wait.

BeforeSelfWakeSwap 

A sleeper decided to wake itself, before its swap.

BeforeHandOff 

The last awake worker, waiting past its margin with work queued, found a worker asleep shallow, before it wakes that worker.

AfterPublishPush 

A publisher queued work, before it reads the awake count.

BetweenWakeSwapAndParkerChange 

A waker made its swap, before it changes the parker.

AfterStopFlagSet 

The destructor set the stop flag, before its wakes.

ScopeWaiterBeforePrepareWait 

A scope's creator that is not a worker found tasks outstanding, before it sets its parker's waiting bit.

ScopeWaiterBeforeWait 

A scope's creator that is not a worker set the waiting bit and its re-check found tasks outstanding, before it waits.

ResumptionPublished 

A coroutine resumption is visible; the publisher released the queue.

AsyncJoinBeforeRegister 

The awaiter loaded a nonzero count, before setting the join flag.

AsyncJoinRegistered 

The awaiter published its resumption, before returning.

AsyncJoinFinisherAfterDecrement 

The last task finished, before any resumption is queued.

AsyncJoinBeforeEnqueue 

The last finisher copied the resumption, before enqueueing it.

ScopeFinisherAfterDecrement 

A finisher's decrement brought its scope's count to zero, before it changes the recorded parker.

ParallelForBeforeClaim 

A loop participant is about to claim a range.

ParallelForAfterClaim 

A loop participant has claimed or exhausted the range.

AfterSearchStart 

A worker counted itself as searching before scanning outside its deque.

WorkerBeforeStartupBarrier 

A new worker is about to acquire the constructor's final roster.

BeforeSearchStart 

Before the worker starts an ordinary or reserved search.

AfterEmptySearch 

The retiring worker still counts as searching after its empty scan.

AfterAdoptedPush 

A slot's deque push was published, before the awake-count check.

BeforeAdoptedStealClaim 

A worker read an adopted entry, before claiming its top index.

◆ WorkerState

enum class donner::tasks::WorkerState : std::uint8_t
strong

A worker's state word.

Enumerator
Awake 

Counted in the scheduler's awake count.

AsleepShallow 

Asleep in the idle loop, or waiting on a scope within its stack margin.

AsleepDeep 

Asleep while waiting on a scope past its stack margin.

AwakeReserved 

Counted awake and holding the incoming search credit.