threads.h File Reference

Go to the source code of this file.

Data Structures

struct  Thread

Defines

#define NUM_THREADS   100
#define THREAD_OK   0
#define THREAD_MUTEX_LOCK   1
#define THREAD_MUTEX_UNLOCK   2

Functions

Threadspawn_thread (void *params, void(*init_fnct)(void *), void(*exit_fnct)(void *))
Threadfind_thread ()
int dest_thread ()
int mutex_state (Thread *, int)
void dest_all_threads (void)
int thread_wait (Thread *, pthread_cond_t *)
int thread_signal (pthread_cond_t *)
int thread_cancle (Thread *)

Variables

dlink_list threadlist
int thread_count

Define Documentation

#define NUM_THREADS   100

Definition at line 7 of file threads.h.

#define THREAD_MUTEX_LOCK   1

Definition at line 10 of file threads.h.

Referenced by mutex_state().

#define THREAD_MUTEX_UNLOCK   2

Definition at line 11 of file threads.h.

Referenced by mutex_state().

#define THREAD_OK   0

Definition at line 9 of file threads.h.


Function Documentation

void dest_all_threads ( void   ) 

dest_all_threads - This destroys all threads within the thread list, and removes their entries from the list.

Returns:
void - No return see logs if errors occure
Note:
This should only be called upon exit as it has the side affect of destroying socketengine threads as it works on an unbias.

Definition at line 267 of file threads.c.

References alog(), dlink_find_delete(), DLINK_FOREACH_SAFE, dlink_free(), has_dest_threads, LOG_ERROR, thread_count, and threadlist.

Referenced by AtExit().

int dest_thread (  ) 

dest_thread - Destroy calling thread and remove it from threadlist all threads are required to call this function before exiting as it insures cleanup and prevents stale thread entires.

Returns:
true/false - This function returns true if the thread exists and can be destroyed. and false otherwise.

Definition at line 207 of file threads.c.

References dlink_find_delete(), DLINK_FOREACH_SAFE, dlink_free(), exit_mutex, thread_count, and threadlist.

Thread* find_thread (  ) 

find_thread - Find a thread by corresponding TID note only threads can call this function as it uses pthread_self to determin the thread we are looking for.

Returns:
Thread* on successfull find of corresponding thread structure NULL on a failure to find the thread.

Definition at line 178 of file threads.c.

References DLINK_FOREACH_SAFE, and threadlist.

int mutex_state ( Thread thread,
int  lock 
)

mutex_state - This function locks the thread mutex found in Thread::mutex it also prevents deadlock from occuring within the threading by implementing pthread_trylock().

Parameters:
thread - A pointer to the thread structure holding our threads data.
lock - weather or not we are to lock our mutex or unlock it
Returns:
true/false True if lock/unlock is successfull false on failure.

Definition at line 140 of file threads.c.

References s_assert, THREAD_MUTEX_LOCK, and THREAD_MUTEX_UNLOCK.

Thread* spawn_thread ( void *  params,
void(*)(void *)  init_fnct,
void(*)(void *)  exit_fnct 
)

spawn_thread - spawns a thread and sets it to the detatched state. This thread I accessable by accessing the structure which is returned upon a successfull call. these threads are globally useable and do not have any predefined behavior, besides being detatched on creation.

Parameters:
params The arguments to be passed to both init_fnct and exit_fnct
init_fnct A function pointer to the entry point of the spawning thread threads jump into this at the begining of normal execution.
exit_fnct This is a pointer to the cleanup function, which is called before a thread destroyes.
Returns:
Thread* upon successful call and null upon failure.
  • Code segments that use threading are required to store the Thread* pointer returned as only threads them selves can look it up via its TID.

Definition at line 59 of file threads.c.

References alog(), dlink_add_tail(), dlink_create(), LOG_ERROR, thread_count, and threadlist.

int thread_cancle ( Thread  ) 

Definition at line 323 of file threads.c.

References alog(), dlink_find_delete(), dlink_free(), LOG_ERROR, thread_count, and threadlist.

int thread_signal ( pthread_cond_t *   ) 

Definition at line 368 of file threads.c.

int thread_wait ( Thread ,
pthread_cond_t *   
)

Definition at line 361 of file threads.c.


Variable Documentation

Definition at line 51 of file threads.h.

Referenced by dest_all_threads(), dest_thread(), spawn_thread(), and thread_cancle().

dlink_list threadlist

Definition at line 38 of file threads.h.

Referenced by dest_all_threads(), dest_thread(), find_thread(), spawn_thread(), and thread_cancle().

Generated on Mon Jul 19 21:53:05 2010 for Omega Security Services by  doxygen 1.6.3