poser
A C framework for POsix SERvices
|
An asynchronous task a thread job can wait for. More...
#include <poser/core/threadpool.h>
Public Member Functions | |
PSC_AsyncTask * | PSC_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. | |
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.
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().
self | the PSC_AsyncTask |
void * PSC_AsyncTask_await | ( | PSC_AsyncTask * | self, |
void * | arg | ||
) |
Wait for completion of an async task.
self | the PSC_AsyncTask |
arg | an optional argument to pass to the async task |
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.
self | the PSC_AsyncTask |
result | an optional result to pass to the awaiting job |
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.
job | the function to call on the main thread |