KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
workqueue.h File Reference

Threaded work queue support. More...

#include <kos/cdefs.h>
#include <kos/thread.h>
#include <stdint.h>
#include <sys/queue.h>

Go to the source code of this file.

Data Structures

struct  workqueue_job_t
 Structure describing a job for the work queue. More...
 

Typedefs

typedef struct workqueue workqueue_t
 

Functions

workqueue_tworkqueue_create (void)
 Create a new work queue.
 
void workqueue_destroy (workqueue_t *wq)
 Destroy a work queue.
 
void workqueue_kill (workqueue_t *wq)
 Stop a work queue from running.
 
void workqueue_enqueue (workqueue_t *wq, workqueue_job_t *job)
 Enqueue a job to a work queue.
 
void workqueue_cancel (workqueue_t *wq, workqueue_job_t *job)
 Cancel a job and remove it from the work queue.
 
kthread_tworkqueue_get_thread (workqueue_t *wq)
 Get a handle to the underlying thread.
 

Detailed Description

Threaded work queue support.

This file contains the API to create and manage work queues.

A work queue is a thread that will execute tasks (aka. jobs) that are enqueued by client code, at a predeterminated moment in time. Multiple jobs can be enqueued. Once a job is executed, it is removed from the execution queue.

Author
Paul Cercueil
See also
kos/thread.h
kos/worker_thread.h

Typedef Documentation

◆ workqueue_t

typedef struct workqueue workqueue_t

Function Documentation

◆ workqueue_cancel()

void workqueue_cancel ( workqueue_t * wq,
workqueue_job_t * job )

Cancel a job and remove it from the work queue.

This function can be used when a job should be removed from a work queue before the job is set to be executed (note that jobs are automatically removed from the work queue right before their execution).

Parameters
wqA pointer to the work queue
jobA pointer to the job to cancel
See also
workqueue_create

◆ workqueue_create()

workqueue_t * workqueue_create ( void )

Create a new work queue.

This function will create a new work queue.

Returns
The new work queue on success, NULL on failure.
See also
workqueue_destroy

◆ workqueue_destroy()

void workqueue_destroy ( workqueue_t * wq)

Destroy a work queue.

This function will destroy a work queue and free up any allocated memory.

Parameters
wqA pointer to the work queue
See also
workqueue_create

◆ workqueue_enqueue()

void workqueue_enqueue ( workqueue_t * wq,
workqueue_job_t * job )

Enqueue a job to a work queue.

This function will enqueue a job to the given work queue. The job's struct must have been initialized properly.

Parameters
wqA pointer to the work queue
jobA pointer to the job to enqueue
See also
workqueue_create

◆ workqueue_get_thread()

kthread_t * workqueue_get_thread ( workqueue_t * wq)

Get a handle to the underlying thread.

Parameters
wqThe workqueue whose thread should be returned.
Returns
A handle to the underlying thread.

◆ workqueue_kill()

void workqueue_kill ( workqueue_t * wq)

Stop a work queue from running.

This function can optionally be called before destroying a work queue. The work queue then stops processing previously or newly enqueued jobs.

Parameters
wqA pointer to the work queue
See also
workqueue_destroy