wxMaxima
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Friends
BackgroundQueue Class Reference

A process-wide thread pool that runs BackgroundTasks, highest priority first. More...

#include <BackgroundQueue.h>

Public Member Functions

 BackgroundQueue (const BackgroundQueue &)=delete
 
BackgroundQueueoperator= (const BackgroundQueue &)=delete
 

Static Public Member Functions

static std::shared_ptr< BackgroundTaskAdd (BackgroundTask::Priority priority, std::function< void(stop_token)> task)
 Enqueue a task at the given priority and return a handle to it.
 
static int Workers ()
 The number of worker threads the pool runs.
 

Friends

class BackgroundTask
 

Detailed Description

A process-wide thread pool that runs BackgroundTasks, highest priority first.

There is exactly one pool, created on first use and holding as many worker threads as we want to run background jobs concurrently (roughly the number of CPU cores). Submitting work via Add() never blocks the calling (usually the GUI) thread: it only appends to a queue and wakes a worker. Workers always empty the high-priority queue before touching the low-priority one, so e.g. the images of a long animation are all loaded before we start compressing the gnuplot sources behind them.

Member Function Documentation

◆ Add()

std::shared_ptr< BackgroundTask > BackgroundQueue::Add ( BackgroundTask::Priority  priority,
std::function< void(stop_token)>  task 
)
static

Enqueue a task at the given priority and return a handle to it.

Does not block. If threading is impossible the task is still queued and run by a worker; callers that must run synchronously should do so themselves instead of calling Add().


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