Thread processing.
More...
|
#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) |
|
|
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
} |
|
The thread object allows executing some code independently of the main process of your application.
◆ safe_int_inc
#define safe_int_inc |
( |
|
__v | ) |
__sync_add_and_fetch((int *) (__v), 1) |
◆ safe_int_dec
#define safe_int_dec |
( |
|
__v | ) |
__sync_sub_and_fetch((int *) (__v), 1) |
◆ safe_int_add
#define safe_int_add |
( |
|
__v, |
|
|
|
inc_val |
|
) |
| __sync_add_and_fetch((int *) (__v), inc_val) |
◆ 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
◆ 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
-
- Returns
- exit code of the thread, usually 1 for error and 0 if normal execution
◆ 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
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
|
◆ gf_th_new()
GF_Thread* gf_th_new |
( |
const char * |
name | ) |
|
Constructs a new thread object
- Parameters
-
name | log 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
-
◆ gf_th_run()
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
-
th | the thread object |
run | the function this thread will call |
par | the 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
-
◆ gf_th_status()
u32 gf_th_status |
( |
GF_Thread * |
th | ) |
|
Gets the thread status
- Parameters
-
- Returns
- thread status
◆ gf_th_set_priority()
void gf_th_set_priority |
( |
GF_Thread * |
th, |
|
|
s32 |
priority |
|
) |
| |
Sets the thread execution priority level.
- Parameters
-
th | the thread object |
priority | the desired priority |
- Note
- this should be used with caution, especially use of real-time priorities.
◆ gf_th_id()
Gets the ID of the current thread the caller is in.
- Returns
- thread ID