ARX  1.2.0
The next-generation open source augmented reality toolkit.
Loading...
Searching...
No Matches
thread_sub.c File Reference
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <ARX/ARUtil/thread_sub.h>
#include <pthread.h>
Include dependency graph for thread_sub.c:

Classes

struct  _THREAD_HANDLE_T

Functions

int threadStartWait (THREAD_HANDLE_T *flag)
 Worker-side.
int threadEndSignal (THREAD_HANDLE_T *flag)
 Worker-side. Notify anyone waiting that the worker has ended.
int threadGetID (THREAD_HANDLE_T *flag)
 Worker-side. Get the 'ID' value passed to the thread's start routine.
void * threadGetArg (THREAD_HANDLE_T *flag)
 Worker-side. Get the 'arg' value passed to the thread's start routine.
THREAD_HANDLE_T * threadInit (int ID, void *arg, void *(*start_routine)(THREAD_HANDLE_T *))
 Client-side, set up.
int threadFree (THREAD_HANDLE_T **flag)
 Client-side, set up. Frees structures associated with the thread handle pointed to by the location pointed to by flag. Thread should already have terminated (i.e. threadWaitQuit() has returned). Location pointed to by flag is set to NULL.
int threadStartSignal (THREAD_HANDLE_T *flag)
 Client-side, communication. Send the worker thread the "start processing" request.
int threadGetStatus (THREAD_HANDLE_T *flag)
 Client-side, communication. Find out (without waiting) whether a worker has ended. 0 = not started or started but not yet ended, 1 = ended.
int threadGetBusyStatus (THREAD_HANDLE_T *flag)
 Client-side, communication. Find out if a worker is currently busy. 0 = worker not started or worker ended, 1 = worker started but not yet ended.
int threadEndWait (THREAD_HANDLE_T *flag)
 Client-side, communication. Wait for thread to end processing.
int threadWaitQuit (THREAD_HANDLE_T *flag)
 Client-side, communication. Tell a thread waiting for the "start processing" request to quit (exit), and wait until this has happened.
int threadGetCPU (void)
 Returns the number of online CPUs in the system.

Function Documentation

◆ threadEndSignal()

int threadEndSignal ( THREAD_HANDLE_T * flag)

Worker-side. Notify anyone waiting that the worker has ended.

Here is the call graph for this function:

◆ threadEndWait()

int threadEndWait ( THREAD_HANDLE_T * flag)

Client-side, communication. Wait for thread to end processing.

Here is the call graph for this function:

◆ threadFree()

int threadFree ( THREAD_HANDLE_T ** flag)

Client-side, set up. Frees structures associated with the thread handle pointed to by the location pointed to by flag. Thread should already have terminated (i.e. threadWaitQuit() has returned). Location pointed to by flag is set to NULL.

Here is the call graph for this function:

◆ threadGetArg()

void * threadGetArg ( THREAD_HANDLE_T * flag)

Worker-side. Get the 'arg' value passed to the thread's start routine.

Here is the call graph for this function:

◆ threadGetBusyStatus()

int threadGetBusyStatus ( THREAD_HANDLE_T * flag)

Client-side, communication. Find out if a worker is currently busy. 0 = worker not started or worker ended, 1 = worker started but not yet ended.

Here is the call graph for this function:

◆ threadGetCPU()

int threadGetCPU ( void )

Returns the number of online CPUs in the system.

Here is the call graph for this function:

◆ threadGetID()

int threadGetID ( THREAD_HANDLE_T * flag)

Worker-side. Get the 'ID' value passed to the thread's start routine.

Here is the call graph for this function:

◆ threadGetStatus()

int threadGetStatus ( THREAD_HANDLE_T * flag)

Client-side, communication. Find out (without waiting) whether a worker has ended. 0 = not started or started but not yet ended, 1 = ended.

Here is the call graph for this function:

◆ threadInit()

THREAD_HANDLE_T * threadInit ( int ID,
void * arg,
void * start_routine (*)(THREAD_HANDLE_T *) )

Client-side, set up.

Create a new thread, and launch start_routine() on it. Returns NULL in case of failure.

Example client structure:

THREAD_HANDLE_T *threadHandle = threadInit(0, NULL, worker);
if (!threadHandle) {
fprintf(stderr, "Error starting thread.\n");
exit(-1);
}
// Ready to do some work:
threadStartSignal(threadHandle);
// Wait for the results.
threadEndWait(threadHandle);
// If all done, quit and cleanup.
threadWaitQuit(threadHandle);
threadFree(&threadHandle);
THREAD_HANDLE_T * threadInit(int ID, void *arg, void *(*start_routine)(THREAD_HANDLE_T *))
Client-side, set up.
Definition thread_sub.c:152
ARUTIL_EXTERN int threadWaitQuit(THREAD_HANDLE_T *flag)
Client-side, communication. Tell a thread waiting for the "start processing" request to quit (exit),...
Definition thread_sub.c:247
ARUTIL_EXTERN int threadEndWait(THREAD_HANDLE_T *flag)
Client-side, communication. Wait for thread to end processing.
Definition thread_sub.c:236
struct _THREAD_HANDLE_T THREAD_HANDLE_T
Definition thread_sub.h:56
ARUTIL_EXTERN int threadFree(THREAD_HANDLE_T **flag)
Client-side, set up. Frees structures associated with the thread handle pointed to by the location po...
Definition thread_sub.c:197
ARUTIL_EXTERN int threadStartSignal(THREAD_HANDLE_T *flag)
Client-side, communication. Send the worker thread the "start processing" request.
Definition thread_sub.c:207
Here is the call graph for this function:

◆ threadStartSignal()

int threadStartSignal ( THREAD_HANDLE_T * flag)

Client-side, communication. Send the worker thread the "start processing" request.

Here is the call graph for this function:

◆ threadStartWait()

int threadStartWait ( THREAD_HANDLE_T * flag)

Worker-side.

Wait for the "start processing" request. Returns 0 if worker should start, or -1 if worker should quit (exit).

Example worker structure:

void *worker(THREAD_HANDLE_T *threadHandle)
{
void *arg = threadHandle->arg; // Get data passed to the worker.
while (threadStartWait(threadHandle) == 0) {
// Do work, probably on arg.
threadEndSignal(threadHandle);
}
// Do cleanup.
return (NULL);
}
void * arg
Definition thread_sub.c:87
int threadStartWait(THREAD_HANDLE_T *flag)
Worker-side.
Definition thread_sub.c:94
int threadEndSignal(THREAD_HANDLE_T *flag)
Worker-side. Notify anyone waiting that the worker has ended.
Definition thread_sub.c:114
Here is the call graph for this function:

◆ threadWaitQuit()

int threadWaitQuit ( THREAD_HANDLE_T * flag)

Client-side, communication. Tell a thread waiting for the "start processing" request to quit (exit), and wait until this has happened.

Here is the call graph for this function: