Veritable Lasagna
An Allocator & Data Structure Library for C.
Loading...
Searching...
No Matches
vl_thread_pthread.c File Reference
#include <time.h>
#include <pthread.h>
#include <unistd.h>
+ Include dependency graph for vl_thread_pthread.c:

Data Structures

struct  vl_posix_thread
 
struct  vl_thread_args
 

Functions

void * vl_ThreadBootstrap (void *arg)
 
vl_thread vlThreadNew (vl_thread_proc threadProc, void *userArg)
 Creates and begins executing a new thread.
 
void vlThreadDelete (vl_thread thread)
 Deletes the specified thread.
 
vl_bool_t vlThreadJoin (vl_thread thread)
 Joins the specified thread, halting the calling thread until the specified thread exits.
 
vl_bool_t vlThreadJoinTimeout (vl_thread thread, vl_uint_t milliseconds)
 Attempts to join the specified thread until a maximum amount of time has passed.
 
vl_thread vlThreadCurrent ()
 Gets the current thread.
 
vl_bool_t vlThreadYield ()
 Yields the execution of the current thread, allowing another thread to take the remainder of its timeslice.
 
void vlThreadSleep (vl_ularge_t milliseconds)
 Sleeps the current thread a specified total number of milliseconds.
 
void vlThreadExit ()
 Exits the calling thread.
 

Variables

vl_posix_thread mainThread
 
VL_THREAD_LOCAL vl_posix_threadcurrentThread = NULL
 Thread local pointer to the metadata of the current thread.
 

Data Structure Documentation

◆ vl_posix_thread

struct vl_posix_thread
+ Collaboration diagram for vl_posix_thread:
Data Fields
pthread_t threadHandle
pthread_cond_t timeoutCondition
pthread_mutex_t timeoutConditionMutex

◆ vl_thread_args

struct vl_thread_args
+ Collaboration diagram for vl_thread_args:
Data Fields
vl_posix_thread * meta
HANDLE threadHandle
vl_thread_proc threadProc
void * userArg

Function Documentation

◆ vl_ThreadBootstrap()

void * vl_ThreadBootstrap ( void * arg)
+ Here is the caller graph for this function:

◆ vlThreadCurrent()

vl_thread vlThreadCurrent ( )

Gets the current thread.

Returns
vl_thread representing the current thread.
+ Here is the caller graph for this function:

◆ vlThreadDelete()

void vlThreadDelete ( vl_thread thread)

Deletes the specified thread.

Warning
This will result in undefined behavior if the thread has not been joined prior to calling this function.
See also
vlThreadJoin
vlThreadJoinTimeout
Parameters
threadwhich thread to delete

◆ vlThreadExit()

void vlThreadExit ( )

Exits the calling thread.

Note
Does not return to the caller.

◆ vlThreadJoin()

vl_bool_t vlThreadJoin ( vl_thread thread)

Joins the specified thread, halting the calling thread until the specified thread exits.

Note
If the specified thread happens to be the main thread, this will return false.
Parameters
thread
Returns
true on success, false on error.

◆ vlThreadJoinTimeout()

vl_bool_t vlThreadJoinTimeout ( vl_thread thread,
vl_uint_t milliseconds )

Attempts to join the specified thread until a maximum amount of time has passed.

Note
Will always return false is trying to join the main thread.
Parameters
thread
milliseconds
Returns
true on success, false on timeout or error.

◆ vlThreadNew()

vl_thread vlThreadNew ( vl_thread_proc threadProc,
void * userArg )

Creates and begins executing a new thread.

Note
May return VL_THREAD_NULL on failure.
Parameters
userArgargument pointer
Returns
thread handle
+ Here is the call graph for this function:

◆ vlThreadSleep()

void vlThreadSleep ( vl_ularge_t milliseconds)

Sleeps the current thread a specified total number of milliseconds.

Parameters
milliseconds

◆ vlThreadYield()

vl_bool_t vlThreadYield ( )

Yields the execution of the current thread, allowing another thread to take the remainder of its timeslice.

Returns
a boolean indicating if the yield operation occurred. May return false if there is no other thread to yield to.

Variable Documentation

◆ currentThread

VL_THREAD_LOCAL vl_posix_thread* currentThread = NULL

Thread local pointer to the metadata of the current thread.

◆ mainThread

vl_posix_thread mainThread