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

A job to be executed on a worker thread. More...

#include <poser/core/threadpool.h>

Public Member Functions

PSC_ThreadJobPSC_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_EventPSC_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.
 

Detailed Description

A job to be executed on a worker thread.

Member Function Documentation

◆ PSC_ThreadJob_canceled()

int PSC_ThreadJob_canceled ( void  )
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.

Returns
1 when the job was canceled, 0 otherwise

◆ PSC_ThreadJob_create()

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.

Parameters
procthe function to run on the worker thread
argthe data to work on
timeoutTicksif non-zero, automatically cancel the job after this many "ticks" (multiples of 500ms)
Returns
a newly created thread job

◆ PSC_ThreadJob_destroy()

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.

Parameters
selfthe PSC_ThreadJob

◆ PSC_ThreadJob_finished()

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.

Parameters
selfthe PSC_ThreadJob
Returns
the finished event

◆ PSC_ThreadJob_hasCompleted()

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.

Parameters
selfthe PSC_ThreadJob
Returns
1 if the job completed, 0 otherwise

◆ PSC_ThreadJob_setStackSize()

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.

Parameters
selfthe PSC_ThreadJob
stackSizethe desired stack size in bytes

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