Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add job system extension #1

Merged
merged 1 commit into from
Apr 16, 2024
Merged

feat: add job system extension #1

merged 1 commit into from
Apr 16, 2024

Conversation

hoffstadt
Copy link
Member

Purpose

The purpose of this pull request is to add an extension that implements a simple but flexible job system. This is an extension built on top of the recently introduced threads API. This extension is ready for 1.0 status (API is stable).

Design

The design is relatively simple. Users submit an array of jobs and receive an atomic counter. This counter's initial value is the number of jobs just submitted. Users later can wait on this counter to reach a specified value.

The atomic counters are managed through a free list (protected by the "latch" mentioned below).

A queue of jobs is protected by an atomic "latch". Threads remove jobs from the queue, execute them, then decrement their associated counter. If there are no jobs, the threads sleep on a conditional variable. When new jobs are pushed, threads are woken up using the conditional variable.

API

// job description
typedef struct _plJobDesc
{
    void (*task)(void* pData);
    void* pData;
} plJobDesc;

// API
typedef struct _plJobI
{
    // setup/shutdown
    void (*initialize)(uint32_t uThreadCount);
    void (*cleanup)(void);

    // typical usage
    void (*run_jobs)        (plJobDesc* ptJobs, uint32_t uJobCount, plAtomicCounter** pptCounter);
    void (*wait_for_counter)(plAtomicCounter* ptCounter, uint32_t uValue);
} plJobI;

@hoffstadt hoffstadt added priority: Normal normal priority state: Approved approved type: Feature related to a new feature extension: Job related to job extension labels Apr 16, 2024
@hoffstadt hoffstadt self-assigned this Apr 16, 2024
@hoffstadt hoffstadt merged commit ca7be59 into master Apr 16, 2024
14 checks passed
@hoffstadt hoffstadt deleted the feature/jobs branch April 16, 2024 23:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extension: Job related to job extension priority: Normal normal priority state: Approved approved type: Feature related to a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant