libgpac
Documentation of the core library of GPAC

Thread processing. More...

+ Collaboration diagram for Thread:

Macros

#define safe_int_inc(__v)   __sync_add_and_fetch((int *) (__v), 1)
 
#define safe_int_dec(__v)   __sync_sub_and_fetch((int *) (__v), 1)
 
#define safe_int_add(__v, inc_val)   __sync_add_and_fetch((int *) (__v), inc_val)
 
#define safe_int_sub(__v, dec_val)   __sync_sub_and_fetch((int *) (__v), dec_val)
 
#define safe_int64_add(__v, inc_val)   __sync_add_and_fetch((int64_t *) (__v), inc_val)
 
#define safe_int64_sub(__v, dec_val)   __sync_sub_and_fetch((int64_t *) (__v), dec_val)
 

Typedefs

typedef u32(* gf_thread_run) (void *par)
 thread run function callback More...
 
typedef struct __tag_thread GF_Thread
 abstracted thread object
 

Enumerations

enum  { GF_THREAD_STATUS_STOP = 0 , GF_THREAD_STATUS_RUN = 1 , GF_THREAD_STATUS_DEAD = 2 }
 Thread states. More...
 
enum  {
  GF_THREAD_PRIORITY_IDLE =0 , GF_THREAD_PRIORITY_LESS_IDLE , GF_THREAD_PRIORITY_LOWEST , GF_THREAD_PRIORITY_LOW ,
  GF_THREAD_PRIORITY_NORMAL , GF_THREAD_PRIORITY_HIGH , GF_THREAD_PRIORITY_HIGHEST , GF_THREAD_PRIORITY_REALTIME ,
  GF_THREAD_PRIORITY_REALTIME_END =255
}
 

Functions

GF_Threadgf_th_new (const char *name)
 thread constructor More...
 
void gf_th_del (GF_Thread *th)
 thread destructor More...
 
GF_Err gf_th_run (GF_Thread *th, gf_thread_run run, void *par)
 thread execution More...
 
void gf_th_stop (GF_Thread *th)
 thread stopping More...
 
u32 gf_th_status (GF_Thread *th)
 thread status query More...
 
void gf_th_set_priority (GF_Thread *th, s32 priority)
 thread priority More...
 
u32 gf_th_id ()
 current thread ID More...
 

Detailed Description

The thread object allows executing some code independently of the main process of your application.

Macro Definition Documentation

◆ safe_int_inc

#define safe_int_inc (   __v)    __sync_add_and_fetch((int *) (__v), 1)

atomic integer increment

◆ safe_int_dec

#define safe_int_dec (   __v)    __sync_sub_and_fetch((int *) (__v), 1)

atomic integer decrement

◆ safe_int_add

#define safe_int_add (   __v,
  inc_val 
)    __sync_add_and_fetch((int *) (__v), inc_val)

atomic integer addition

◆ safe_int_sub

#define safe_int_sub (   __v,
  dec_val 
)    __sync_sub_and_fetch((int *) (__v), dec_val)

atomic integer subtraction

◆ safe_int64_add

#define safe_int64_add (   __v,
  inc_val 
)    __sync_add_and_fetch((int64_t *) (__v), inc_val)

atomic large integer addition

◆ safe_int64_sub

#define safe_int64_sub (   __v,
  dec_val 
)    __sync_sub_and_fetch((int64_t *) (__v), dec_val)

atomic large integer subtraction

Typedef Documentation

◆ gf_thread_run

typedef u32(* gf_thread_run) (void *par)

The gf_thread_run type is the type for the callback of the gf_thread_run function

Parameters
paropaque user data
Returns
exit code of the thread, usually 1 for error and 0 if normal execution

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Indicates the execution status of a thread

Enumerator
GF_THREAD_STATUS_STOP 

the thread has been initialized but is not started yet

GF_THREAD_STATUS_RUN 

the thread is running

GF_THREAD_STATUS_DEAD 

the thread has exited its body function

◆ anonymous enum

anonymous enum

thread priorities

Enumerator
GF_THREAD_PRIORITY_IDLE 

Idle Priority

GF_THREAD_PRIORITY_LESS_IDLE 

Less Idle Priority

GF_THREAD_PRIORITY_LOWEST 

Lowest Priority

GF_THREAD_PRIORITY_LOW 

Low Priority

GF_THREAD_PRIORITY_NORMAL 

Normal Priority (the default one)

GF_THREAD_PRIORITY_HIGH 

High Priority

GF_THREAD_PRIORITY_HIGHEST 

Highest Priority

GF_THREAD_PRIORITY_REALTIME 

First real-time priority

GF_THREAD_PRIORITY_REALTIME_END 

Last real-time priority

Function Documentation

◆ gf_th_new()

GF_Thread* gf_th_new ( const char *  name)

Constructs a new thread object

Parameters
namelog name of the thread if any
Returns
new thread object

◆ gf_th_del()

void gf_th_del ( GF_Thread th)

Kills the thread if running and destroys the object

Parameters
ththe thread object

◆ gf_th_run()

GF_Err gf_th_run ( GF_Thread th,
gf_thread_run  run,
void *  par 
)

Executes the thread with the given function

Note
A thread may be run several times but cannot be run twice in the same time.
Parameters
ththe thread object
runthe function this thread will call
parthe argument to the function the thread will call
Returns
error if any

◆ gf_th_stop()

void gf_th_stop ( GF_Thread th)

Waits for the thread exit until return

Parameters
ththe thread object

◆ gf_th_status()

u32 gf_th_status ( GF_Thread th)

Gets the thread status

Parameters
ththe thread object
Returns
thread status

◆ gf_th_set_priority()

void gf_th_set_priority ( GF_Thread th,
s32  priority 
)

Sets the thread execution priority level.

Parameters
ththe thread object
prioritythe desired priority
Note
this should be used with caution, especially use of real-time priorities.

◆ gf_th_id()

u32 gf_th_id ( )

Gets the ID of the current thread the caller is in.

Returns
thread ID