DTS Application Library
0.2.3
Application library containing referenced objects and interfaces to common libraries
|
Functions for starting and managing threads. More...
Files | |
file | thread.c |
Functions for starting and managing threads. | |
Data Structures | |
struct | thread_pvt |
thread struct used to create threads data needs to be first element More... | |
struct | threadcontainer |
Global threads data. More... | |
Typedefs | |
typedef void(* | threadcleanup )(void *) |
Function called after thread termination. More... | |
typedef void *(* | threadfunc )(void *) |
Thread function. More... | |
typedef int(* | threadsighandler )(int, void *) |
Thread signal handler function. More... | |
Enumerations | |
enum | thread_option_flags { THREAD_OPTION_CANCEL = 1 << 0, THREAD_OPTION_JOINABLE = 1 << 1, THREAD_OPTION_RETURN = 1 << 2 } |
Options supplied to framework_mkthread all defaults are unset. More... | |
enum | threadopt { TL_THREAD_NONE = 1 << 0, TL_THREAD_RUN = 1 << 1, TL_THREAD_DONE = 1 << 2, TL_THREAD_JOIN = 1 << 3, TL_THREAD_STOP = 1 << 4, TL_THREAD_CAN_CANCEL = 1 << 16, TL_THREAD_JOINABLE = 1 << 17, TL_THREAD_RETURN = 1 << 18 } |
Thread status a thread can be disabled by unsetting TL_THREAD_RUN. More... | |
Functions | |
int | framework_threadok () |
let threads check there status. More... | |
int | startthreads (void) |
Initialise the threadlist and start manager thread. More... | |
void | stopthreads (int join) |
Signal manager to stop and cancel all running threads. More... | |
struct thread_pvt * | framework_mkthread (threadfunc func, threadcleanup cleanup, threadsighandler sig_handler, void *data, int flags) |
create a thread result must be unreferenced More... | |
void | jointhreads (void) |
Join the manager thread. More... | |
int | thread_signal (int sig) |
Handle signal if its for me. More... | |
Variables | |
struct threadcontainer * | threads = NULL |
Thread control data. More... | |
int | thread_can_start = 1 |
Automatically start manager thread. More... | |
Functions for starting and managing threads.
typedef void(* threadcleanup)(void *) |
Function called after thread termination.
data | Reference of thread data. |
typedef void*(* threadfunc)(void *) |
typedef int(* threadsighandler)(int, void *) |
Thread signal handler function.
data | Reference of thread data. |
enum thread_option_flags |
Options supplied to framework_mkthread all defaults are unset.
Definition at line 118 of file dtsapp.h.
enum threadopt |
Thread status a thread can be disabled by unsetting TL_THREAD_RUN.
Definition at line 36 of file thread.c.
struct thread_pvt* framework_mkthread | ( | threadfunc | func, |
threadcleanup | cleanup, | ||
threadsighandler | sig_handler, | ||
void * | data, | ||
int | flags | ||
) |
create a thread result must be unreferenced
func | Function to run thread on. |
cleanup | Cleanup function to run. |
sig_handler | Thread signal handler. |
data | Data to pass to callbacks. |
flags | Options of thread_option_flags passed |
Definition at line 387 of file thread.c.
References addtobucket(), thread_pvt::cleanup, thread_pvt::data, thread_pvt::flags, thread_pvt::func, threadcontainer::list, threadcontainer::manager, objalloc(), objlock(), objref(), objunlock(), objunref(), setflag, thread_pvt::sighandler, startthreads(), testflag, thread_pvt::thr, thread_can_start, TL_THREAD_RETURN, and TL_THREAD_RUN.
Referenced by nf_ctrack_trace(), startthreads(), and unixsocket_server().
int framework_threadok | ( | void | ) |
let threads check there status.
Definition at line 143 of file thread.c.
References objunref(), testflag, thread_pvt::thr, and TL_THREAD_RUN.
void jointhreads | ( | void | ) |
Join the manager thread.
This will be done when you have issued stopthreads and are waiting or have completed the program and want to let the threads continue. for threads to exit.
Definition at line 450 of file thread.c.
References threadcontainer::manager, objlock(), objref(), objunlock(), objunref(), setflag, thread_pvt::thr, and TL_THREAD_JOIN.
int startthreads | ( | void | ) |
Initialise the threadlist and start manager thread.
Definition at line 268 of file thread.c.
References create_bucketlist(), framework_mkthread(), threadcontainer::list, threadcontainer::manager, objalloc(), objref(), objunref(), THREAD_OPTION_JOINABLE, and THREAD_OPTION_RETURN.
Referenced by framework_mkthread().
void stopthreads | ( | int | join | ) |
Signal manager to stop and cancel all running threads.
This should always be called at shutdown if there have been threads started.
join | A non zero value to join the manager thread after flaging the shutdown. |
Definition at line 303 of file thread.c.
References threadcontainer::manager, objlock(), objref(), objunlock(), objunref(), setflag, thread_pvt::thr, TL_THREAD_JOIN, and TL_THREAD_STOP.
Referenced by framework_init().
int thread_signal | ( | int | sig | ) |
Handle signal if its for me.
find the thread the signal was delivered to if the signal was handled returns 1 if the thread could not be handled returns -1 returns 0 if no thread is found NB sending a signal to the current thread while threads is locked will cause a deadlock.
sig | Signal to pass. |
Definition at line 496 of file thread.c.
References objunref().
int thread_can_start = 1 |
Automatically start manager thread.
If threads have not been started and a thread is created the manager thread will be started. once threads have stoped this will be set to zero manually starting startthreads will be possible.
Definition at line 92 of file thread.c.
Referenced by framework_mkthread().
struct threadcontainer* threads = NULL |