Cyber Garage Portable Runtime (CGPR) for C
thread.h File Reference
#include <cgpr/util/cond.h>
#include <cgpr/util/list.h>
#include <cgpr/util/time.h>
#include <pthread.h>
#include <signal.h>

Data Structures

struct  _CGThread
 The generic wrapper struct for mUPnP's threads. More...
 

Macros

#define CG_THREAD_MIN_SLEEP   1000
 
#define cg_thread_next(thread)
 
#define cg_thread_remove(thread)
 
#define cg_threadlist_clear(threadList)
 
#define cg_threadlist_size(threadList)
 
#define cg_threadlist_gets(threadList)
 
#define cg_threadlist_add(threadList, thread)
 
#define cg_threadlist_remove(thread)
 

Typedefs

typedef struct _CGThread CGThread
 The generic wrapper struct for mUPnP's threads.
 
typedef struct _CGThread CGThreadList
 
typedef void(* CG_THREAD_FUNC) (CGThread *)
 

Functions

CGThreadcg_thread_new (void)
 
CGThreadcg_thread_self (void)
 
bool cg_thread_delete (CGThread *thread)
 
bool cg_thread_start (CGThread *thread)
 
bool cg_thread_stop (CGThread *thread)
 
bool cg_thread_stop_with_cond (CGThread *thread, CGCond *cond)
 
bool cg_thread_restart (CGThread *thread)
 
bool cg_thread_isrunnable (CGThread *thread)
 
void cg_thread_setaction (CGThread *thread, CG_THREAD_FUNC actionFunc)
 
void cg_thread_setuserdata (CGThread *thread, void *data)
 
void * cg_thread_getuserdata (CGThread *thread)
 
CGThreadListcg_threadlist_new (void)
 
void cg_threadlist_delete (CGThreadList *threadList)
 
bool cg_threadlist_start (CGThreadList *threadList)
 
bool cg_threadlist_stop (CGThreadList *threadList)
 

Macro Definition Documentation

◆ CG_THREAD_MIN_SLEEP

#define CG_THREAD_MIN_SLEEP   1000

◆ cg_thread_next

#define cg_thread_next ( thread)
Value:
CGList * cg_list_next(CGList *list)
Definition list.c:216
The generic list interface in mUPnP.
Definition list.h:69
The generic wrapper struct for mUPnP's threads.
Definition thread.h:46

◆ cg_thread_remove

#define cg_thread_remove ( thread)
Value:
bool cg_list_remove(CGList *list)
Definition list.c:131

◆ cg_threadlist_add

#define cg_threadlist_add ( threadList,
thread )
Value:
cg_list_add((CGList*)threadList, (CGList*)thread)
bool cg_list_add(CGList *headList, CGList *list)
Definition list.c:114

Add a thread into a thread list

Parameters
threadListThe thread list in question
threadThe thread to add to the list

◆ cg_threadlist_clear

#define cg_threadlist_clear ( threadList)
Value:
bool cg_thread_delete(CGThread *thread)
Definition thread.c:94
bool cg_list_clear(CGList *headList, CG_LIST_DESTRUCTORFUNC dstructorFunc)
Definition list.c:234
void(* CG_LIST_DESTRUCTORFUNC)(void *)
Definition list.h:42

Clear the contents of a thread list

Parameters
threadListThread list in question

◆ cg_threadlist_gets

#define cg_threadlist_gets ( threadList)
Value:
(CGThread*)cg_list_next((CGList*)threadList)

Get the first actual item from a thread list to use as an iterator

Parameters
threadListThe thread list in question

◆ cg_threadlist_remove

#define cg_threadlist_remove ( thread)
Value:

Remove a thread from thread list

Parameters
threadListThe thread list in question
threadThe thread to be removed

◆ cg_threadlist_size

#define cg_threadlist_size ( threadList)
Value:
cg_list_size((CGList*)threadList)
size_t cg_list_size(CGList *headList)
Definition list.c:55

Get the size of a thread list

Parameters
threadListThe thread list in question

Typedef Documentation

◆ CG_THREAD_FUNC

typedef void(* CG_THREAD_FUNC) (CGThread *)

Prototype for the threads' worker functions

◆ CGThread

typedef struct _CGThread CGThread

The generic wrapper struct for mUPnP's threads.

This wrapper has been created to enable 100% code compatibility between different platforms (Linux, Win32 etc..)

◆ CGThreadList

typedef struct _CGThread CGThreadList

Function Documentation

◆ cg_thread_delete()

bool cg_thread_delete ( CGThread * thread)

Stop and destroy a thread.

Parameters
threadThread to destroy

◆ cg_thread_getuserdata()

void * cg_thread_getuserdata ( CGThread * thread)

Get the user data pointer

Parameters
threadThread from which to get the pointer

◆ cg_thread_isrunnable()

bool cg_thread_isrunnable ( CGThread * thread)

Check if a thread has been started

Parameters
threadThread to check

◆ cg_thread_new()

CGThread * cg_thread_new ( void )

Create a new thread

◆ cg_thread_restart()

bool cg_thread_restart ( CGThread * thread)

Restart a thread. Essentially calls cg_thread_stop() and cg_thread_start()

Parameters
threadThread to restart

◆ cg_thread_self()

CGThread * cg_thread_self ( void )

Get a self reference to thread.

◆ cg_thread_setaction()

void cg_thread_setaction ( CGThread * thread,
CG_THREAD_FUNC actionFunc )

Set the thread's worker function.

Parameters
threadThread struct
actionFuncFunction pointer to set as the worker function

◆ cg_thread_setuserdata()

void cg_thread_setuserdata ( CGThread * thread,
void * data )

Set the user data pointer

Parameters
threadThread struct
dataPointer to user data

◆ cg_thread_start()

bool cg_thread_start ( CGThread * thread)

Start a thread (must be created first with ch_thread_new())

Parameters
threadThread to start

◆ cg_thread_stop()

bool cg_thread_stop ( CGThread * thread)

Stop a running thread.

Parameters
threadThread to stop

◆ cg_thread_stop_with_cond()

bool cg_thread_stop_with_cond ( CGThread * thread,
CGCond * cond )

Stop the running thread and signal the given CGCond.

◆ cg_threadlist_delete()

void cg_threadlist_delete ( CGThreadList * threadList)

Destroy a thread list

Parameters
threadListThe thread list in question

◆ cg_threadlist_new()

CGThreadList * cg_threadlist_new ( void )

Create a new thread list

Returns
Thread list

◆ cg_threadlist_start()

bool cg_threadlist_start ( CGThreadList * threadList)

Start all threads in the thread list

Parameters
threadListThe thread list in question

◆ cg_threadlist_stop()

bool cg_threadlist_stop ( CGThreadList * threadList)

Stop all threads in the thread list

Parameters
threadListThe thread list in question