lwpa  0.1.0
LightWeight Platform Abstraction (lwpa)
View other versions:
lwpa_thread

Overview

Platform-neutral threads.

#include "lwpa_thread.h"

Data Structures

struct  LwpaThreadParams
 A set of parameters for an lwpa_thread. More...
 

Macros

#define LWPA_THREAD_DEFAULT_PRIORITY
 The platform-specific default priority for an lwpa_thread. More...
 
#define LWPA_THREAD_DEFAULT_STACK
 The plaform-specific default stack size for an lwpa_thread. More...
 
#define LWPA_THREAD_DEFAULT_NAME
 The default name for an lwpa_thread.
 
#define LWPA_THREAD_NAME_MAX_LENGTH
 The maximum length of an lwpa_thread name C-string.
 

Typedefs

typedef struct LwpaThreadParams LwpaThreadParams
 A set of parameters for an lwpa_thread.
 
typedef UNDEFINED lwpa_thread_t
 The thread identifier. More...
 

Functions

bool lwpa_thread_create (lwpa_thread_t *id, const LwpaThreadParams *params, void(*thread_fn)(void *), void *thread_arg)
 Create a new thread. More...
 
bool lwpa_thread_stop (lwpa_thread_t *id, int wait_ms)
 Stop a thread. More...
 
void lwpa_thread_sleep (int sleep_ms)
 Provides a platform-neutral sleep. More...
 

Macro Definition Documentation

◆ LWPA_THREAD_DEFAULT_PRIORITY

#define LWPA_THREAD_DEFAULT_PRIORITY

The platform-specific default priority for an lwpa_thread.

Note that thread priority is not valid on all platforms.

◆ LWPA_THREAD_DEFAULT_STACK

#define LWPA_THREAD_DEFAULT_STACK

The plaform-specific default stack size for an lwpa_thread.

Note that thread stack size is not valid on all platforms.

Typedef Documentation

◆ lwpa_thread_t

typedef UNDEFINED lwpa_thread_t

The thread identifier.

Depending on the platform, this could be a scalar type or a struct.

Function Documentation

◆ lwpa_thread_create()

bool lwpa_thread_create ( lwpa_thread_t id,
const LwpaThreadParams params,
void(*)(void *)  thread_fn,
void *  thread_arg 
)

Create a new thread.

If your application has exit/shutdown behavior (i.e. it is a non-embedded application), it's good practice to always pair this with a call to lwpa_thread_stop() on exit. On some platforms, extra signaling resources are allocated when the thread is created that are not deallocated unless lwpa_thread_stop() is called.

Parameters
[out]idIdentifier for the thread that was created.
[in]paramsThread parameters for the thread to create
[in]thread_fnPointer to function that should be called from the new thread. This function takes one void* argument and returns void.
[in]thread_argArgument to the function called from the new thread.
Returns
true (the thread was created) or false (the thread was not created).

◆ lwpa_thread_sleep()

void lwpa_thread_sleep ( int  sleep_ms)

Provides a platform-neutral sleep.

Parameters
[in]sleep_msHow long to sleep, in milliseconds.

◆ lwpa_thread_stop()

bool lwpa_thread_stop ( lwpa_thread_t id,
int  wait_ms 
)

Stop a thread.

On some platforms, wait_ms is ignored and you always wait forever for a thread to stop.

Parameters
[in]idIdentifier for the thread to stop.
[in]wait_msHow long to wait for the thread to stop, in milliseconds (use LWPA_WAIT_FOREVER to wait indefinitely).
Returns
true (the thread was stopped) or false (an error occurred).