poser
A C framework for POsix SERvices
Loading...
Searching...
No Matches
PSC_AsyncTask Class Reference

An asynchronous task a thread job can wait for. More...

#include <poser/core/threadpool.h>

Public Member Functions

PSC_AsyncTaskPSC_AsyncTask_create (PSC_AsyncTaskJob job)
 PSC_AsyncTask default constructor.
 
void * PSC_AsyncTask_await (PSC_AsyncTask *self, void *arg)
 Wait for completion of an async task.
 
void * PSC_AsyncTask_arg (PSC_AsyncTask *self)
 Get the argument of an async task.
 
void PSC_AsyncTask_complete (PSC_AsyncTask *self, void *result)
 Complete an async task.
 

Static Public Member Functions

int PSC_AsyncTask_awaitIsBlocking (void)
 Check whether PSC_AsyncTask_await() will block.
 

Detailed Description

An asynchronous task a thread job can wait for.

When the library is built on a system supporting user context switching with POSIX-1.2001 getcontext() and friends, the thread is released for other thread jobs while waiting, otherwise the worker thread will be blocked.

No destructor is offered, the task destroys itself on completion.

Member Function Documentation

◆ PSC_AsyncTask_arg()

void * PSC_AsyncTask_arg ( PSC_AsyncTask self)

Get the argument of an async task.

This is meant to be called on the main thread from a PSC_AsyncTaskJob to get the optional argument passed to PSC_AsyncTask_await().

Parameters
selfthe PSC_AsyncTask
Returns
the task's argument

◆ PSC_AsyncTask_await()

void * PSC_AsyncTask_await ( PSC_AsyncTask self,
void *  arg 
)

Wait for completion of an async task.

Parameters
selfthe PSC_AsyncTask
argan optional argument to pass to the async task
Returns
the result given to PSC_AsyncTask_complete()

◆ PSC_AsyncTask_awaitIsBlocking()

int PSC_AsyncTask_awaitIsBlocking ( void  )
static

Check whether PSC_AsyncTask_await() will block.

This method tells at runtime whether awaiting a PSC_AsyncTask will always block the worker thread (which is the case on systems without support for POSIX user context switching), or only when the job's stack size is set to zero. It may be used to configure a suitable number of worker threads per CPU.

Returns
1 if PSC_AsyncTask_await() always blocks, 0 if it only blocks when a stack size of 0 is configured.

◆ PSC_AsyncTask_complete()

void PSC_AsyncTask_complete ( PSC_AsyncTask self,
void *  result 
)

Complete an async task.

This must be called from the main thread to allow the thread job awaiting the async task to continue.

Parameters
selfthe PSC_AsyncTask
resultan optional result to pass to the awaiting job

◆ PSC_AsyncTask_create()

PSC_AsyncTask * PSC_AsyncTask_create ( PSC_AsyncTaskJob  job)

PSC_AsyncTask default constructor.

Creates a new PSC_AsyncTask that will call the given function on the main thread when awaited.

Parameters
jobthe function to call on the main thread
Returns
a newly created PSC_AsyncTask

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