C-chat
Classes | Macros | Typedefs | Functions
threads.h File Reference

An OS-agnostic API to manipulate threads. More...

Go to the source code of this file.

Classes

struct  Thread
 Represents a thread. More...
 

Macros

#define THREAD_ENTRY_POINT   THREAD_RETURN_TYPE THREAD_CALL_TYPE
 A macro to declare a function meant to be used as an entry point for a thread.
 

Typedefs

typedef THREAD_RETURN_TYPE(THREAD_CALL_TYPE * FP_THREAD) (void *)
 
typedef FP_THREAD THREAD_FUNCTION_POINTER
 The type for a valid thread entry point.
 
typedef struct Thread Thread
 

Functions

Thread createThread (THREAD_FUNCTION_POINTER entryPoint, void *data)
 Creates and starts a thread. More...
 
void destroyThread (Thread *thread)
 Destroys the given thread. More...
 
void joinThread (Thread *thread)
 Waits for the given thread to finish. More...
 

Detailed Description

An OS-agnostic API to manipulate threads.

Function Documentation

◆ createThread()

Thread createThread ( THREAD_FUNCTION_POINTER  entryPoint,
void *  data 
)

Creates and starts a thread.

Creates a thread which the entry point will be the given function. The given entry point MUST be declared as a thread entry point. Example :

THREAD_ENTRY_POINT entryPointName(void* data) { return EXIT_SUCCESS; }

Parameters
entryPointThe entry point for the thread
dataA pointer to be passed to thread's entry point
Returns
the created thread

◆ destroyThread()

void destroyThread ( Thread thread)

Destroys the given thread.

Parameters
threadA pointer to the thread to destroy

◆ joinThread()

void joinThread ( Thread thread)

Waits for the given thread to finish.

Parameters
threadA pointer to the thread to wait