poser
A C framework for POsix SERvices
|
A job to be executed on a worker thread. More...
#include <poser/core/threadpool.h>
Public Member Functions | |
PSC_ThreadJob * | PSC_ThreadJob_create (PSC_ThreadProc proc, void *arg, int timeoutTicks) |
Create a new thread job. | |
void | PSC_ThreadJob_setStackSize (PSC_ThreadJob *self, size_t stackSize) |
Configure the stack size for a thread job. | |
PSC_Event * | PSC_ThreadJob_finished (PSC_ThreadJob *self) |
The job finished. | |
int | PSC_ThreadJob_hasCompleted (const PSC_ThreadJob *self) |
Determine whether the job completed. | |
void | PSC_ThreadJob_destroy (PSC_ThreadJob *self) |
PSC_ThreadJob destructor. | |
Static Public Member Functions | |
int | PSC_ThreadJob_canceled (void) |
Check whether a job was canceled. | |
A job to be executed on a worker thread.
|
static |
Check whether a job was canceled.
This must only be called from within a PSC_ThreadProc. It signals whether the job was canceled, in that case, the PSC_ThreadProc should exit quickly.
PSC_ThreadJob * PSC_ThreadJob_create | ( | PSC_ThreadProc | proc, |
void * | arg, | ||
int | timeoutTicks | ||
) |
Create a new thread job.
Creates a new job to be executed on a worker thread. Unless the library was built on a system without POSIX user context switching support, the job executes on its own private stack with a default size of 64 kiB. If that is not enough for the job, make sure to configure a suitable size with PSC_ThreadJob_setStackSize() before scheduling the job to avoid stack overflow crashes.
proc | the function to run on the worker thread |
arg | the data to work on |
timeoutTicks | if non-zero, automatically cancel the job after this many "ticks" (multiples of 500ms) |
void PSC_ThreadJob_destroy | ( | PSC_ThreadJob * | self | ) |
PSC_ThreadJob destructor.
Destroys the thread job.
Note that once the job was scheduled, PSC_ThreadPool will automatically destroy it when it completed or is canceled.
self | the PSC_ThreadJob |
PSC_Event * PSC_ThreadJob_finished | ( | PSC_ThreadJob * | self | ) |
The job finished.
This event fires when the thread job finished, either because it completed or because it was canceled.
self | the PSC_ThreadJob |
int PSC_ThreadJob_hasCompleted | ( | const PSC_ThreadJob * | self | ) |
Determine whether the job completed.
This can be called when PSC_ThreadJob_finished() fired to know whether the job completed successfully.
self | the PSC_ThreadJob |
void PSC_ThreadJob_setStackSize | ( | PSC_ThreadJob * | self, |
size_t | stackSize | ||
) |
Configure the stack size for a thread job.
Configures the size of the private stack for executing this thread job. When set to 0, awaiting a PSC_AsyncTask on this job will block the worker thread it is running on. When the library was built on a system without POSIX user context switching support, the stack size is always 0 and this call is silently ignored.
The default size is 64 kiB (64 * 1024), unless user context switching is not available.
self | the PSC_ThreadJob |
stackSize | the desired stack size in bytes |