Reduct  v4.0.5-1-g4851deb
A functional and immutable language.
Loading...
Searching...
No Matches
Task

Detailed Description

Data Structures

struct  reduct_task_id_t
 Task ID structure. More...
 
struct  reduct_task_t
 Task structure. More...
 
struct  reduct_task_global_t
 Global thread-related state structure. More...
 

Macros

#define REDUCT_TASK_QUEUE_MAX   256
 The maximum number of tasks.
 
#define REDUCT_TASK_SPIN_MAX   1000
 The maximum number of times to spin while waiting for work to be ready.
 
#define REDUCT_TASK_ID_INVALID   ((reduct_task_id_t){ .index = UINT16_MAX, .generation = UINT16_MAX })
 Invalid task ID.
 

Functions

REDUCT_API int reduct_task_worker (void *arg)
 Worker thread main loop..
 
REDUCT_API void reduct_task_global_init (reduct_task_global_t *global)
 Initialize a global task state.
 
REDUCT_API void reduct_task_global_deinit (reduct_task_global_t *global)
 Deinitialize a global task state.
 
REDUCT_API bool reduct_task_create (struct reduct *reduct, void(*func)(struct reduct *reduct, void *arg), void *arg, reduct_task_id_t *outId)
 Try to create a new task.
 
REDUCT_API void reduct_task_join (struct reduct *reduct, reduct_task_id_t id)
 Wait for a task to finish.
 
static REDUCT_ALWAYS_INLINE uint64_t reduct_task_queue_size (reduct_task_global_t *global)
 Retrieve the number of pending tasks.
 
REDUCT_API void reduct_task_barrier (struct reduct *reduct)
 Barrier function to ensure all threads have either reached the barrier.
 

Macro Definition Documentation

◆ REDUCT_TASK_QUEUE_MAX

#define REDUCT_TASK_QUEUE_MAX   256

The maximum number of tasks.

Definition at line 23 of file task.h.

◆ REDUCT_TASK_SPIN_MAX

#define REDUCT_TASK_SPIN_MAX   1000

The maximum number of times to spin while waiting for work to be ready.

Definition at line 25 of file task.h.

◆ REDUCT_TASK_ID_INVALID

#define REDUCT_TASK_ID_INVALID   ((reduct_task_id_t){ .index = UINT16_MAX, .generation = UINT16_MAX })

Invalid task ID.

Definition at line 38 of file task.h.

Function Documentation

◆ reduct_task_worker()

REDUCT_API int reduct_task_worker ( void *  arg)

Worker thread main loop..

Parameters
argPointer to the reduct_t structure of the thread.

◆ reduct_task_global_init()

REDUCT_API void reduct_task_global_init ( reduct_task_global_t global)

Initialize a global task state.

Parameters
globalPointer to the global task state to initialize.

◆ reduct_task_global_deinit()

REDUCT_API void reduct_task_global_deinit ( reduct_task_global_t global)

Deinitialize a global task state.

Parameters
globalPointer to the global task state to deinitialize.

◆ reduct_task_create()

REDUCT_API bool reduct_task_create ( struct reduct *  reduct,
void(*)(struct reduct *reduct, void *arg)  func,
void *  arg,
reduct_task_id_t outId 
)

Try to create a new task.

Parameters
reductPointer to the Reduct structure.
funcThe function to execute in the task.
argThe argument to pass to the function.
outIdPointer to store the ID of the created task.
Returns
true if the task was created, false if the queue is full.

◆ reduct_task_join()

REDUCT_API void reduct_task_join ( struct reduct *  reduct,
reduct_task_id_t  id 
)

Wait for a task to finish.

Parameters
reductPointer to the Reduct structure.
idThe id of the task to wait for.
Here is the caller graph for this function:

◆ reduct_task_queue_size()

static REDUCT_ALWAYS_INLINE uint64_t reduct_task_queue_size ( reduct_task_global_t global)
inlinestatic

Retrieve the number of pending tasks.

Parameters
globalPointer to the global task state.
Returns
The number of pending tasks in the queue.

Definition at line 115 of file task.h.

◆ reduct_task_barrier()

REDUCT_API void reduct_task_barrier ( struct reduct *  reduct)

Barrier function to ensure all threads have either reached the barrier.

Once the function returns all threads that have reached the barrier will be unblocked.

Parameters
reductPointer to the Reduct structure.