CyberLink for C

cthread.h File Reference

#include <cybergarage/typedef.h>
#include <cybergarage/util/clist.h>
#include <cybergarage/util/ccond.h>
#include <cybergarage/util/ctime.h>
#include <pthread.h>
#include <signal.h>

Data Structures

struct  _CgThread
 The generic wrapper struct for CyberLinkC's threads. More...

Defines

#define CG_THREAD_MIN_SLEEP   1000
#define cg_thread_next(thread)   (CgThread *)cg_list_next((CgList *)thread)
#define cg_thread_remove(thread)   cg_list_remove((CgList *)thread)
#define cg_threadlist_clear(threadList)   cg_list_clear((CgList *)threadList, (CG_LIST_DESTRUCTORFUNC)cg_thread_delete)
#define cg_threadlist_size(threadList)   cg_list_size((CgList *)threadList)
#define cg_threadlist_gets(threadList)   (CgThread *)cg_list_next((CgList *)threadList)
#define cg_threadlist_add(threadList, thread)   cg_list_add((CgList *)threadList, (CgList *)thread)
#define cg_threadlist_remove(thread)   cg_list_remove((CgList *)thread)

Typedefs

typedef struct _CgThread CgThread
 The generic wrapper struct for CyberLinkC's threads.
typedef struct _CgThread CgThreadList
typedef void(* CG_THREAD_FUNC )(CgThread *)

Functions

CgThread * cg_thread_new ()
CgThread * cg_thread_self ()
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)
CgThreadList * cg_threadlist_new ()
void cg_threadlist_delete (CgThreadList *threadList)
BOOL cg_threadlist_start (CgThreadList *threadList)
BOOL cg_threadlist_stop (CgThreadList *threadList)

Define Documentation

#define CG_THREAD_MIN_SLEEP   1000
#define cg_thread_next (   thread)    (CgThread *)cg_list_next((CgList *)thread)
#define cg_thread_remove (   thread)    cg_list_remove((CgList *)thread)
#define cg_threadlist_add (   threadList,
  thread 
)    cg_list_add((CgList *)threadList, (CgList *)thread)

Add a thread into a thread list

Parameters:
threadListThe thread list in question
threadThe thread to add to the list
#define cg_threadlist_clear (   threadList)    cg_list_clear((CgList *)threadList, (CG_LIST_DESTRUCTORFUNC)cg_thread_delete)

Clear the contents of a thread list

Parameters:
threadListThread list in question
#define cg_threadlist_gets (   threadList)    (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
#define cg_threadlist_remove (   thread)    cg_list_remove((CgList *)thread)

Remove a thread from thread list

Parameters:
threadListThe thread list in question
threadThe thread to be removed
#define cg_threadlist_size (   threadList)    cg_list_size((CgList *)threadList)

Get the size of a thread list

Parameters:
threadListThe thread list in question

Typedef Documentation

typedef void(* CG_THREAD_FUNC)(CgThread *)

Prototype for the threads' worker functions

typedef struct _CgThread CgThread

The generic wrapper struct for CyberLinkC's threads.

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

typedef struct _CgThread CgThreadList

Function Documentation

BOOL cg_thread_delete ( CgThread *  thread)

Stop and destroy a thread.

Parameters:
threadThread to destroy
void* cg_thread_getuserdata ( CgThread *  thread)

Get the user data pointer

Parameters:
threadThread from which to get the pointer
BOOL cg_thread_isrunnable ( CgThread *  thread)

Check if a thread has been started

Parameters:
threadThread to check
CgThread* cg_thread_new ( )

Create a new thread

BOOL cg_thread_restart ( CgThread *  thread)

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

Parameters:
threadThread to restart
CgThread* cg_thread_self ( )

Get a self reference to thread.

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
void cg_thread_setuserdata ( CgThread *  thread,
void *  data 
)

Set the user data pointer

Parameters:
threadThread struct
dataPointer to user data
BOOL cg_thread_start ( CgThread *  thread)

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

Parameters:
threadThread to start
BOOL cg_thread_stop ( CgThread *  thread)

Stop a running thread.

Parameters:
threadThread to stop
BOOL cg_thread_stop_with_cond ( CgThread *  thread,
CgCond *  cond 
)

Stop the running thread and signal the given CGCond.

void cg_threadlist_delete ( CgThreadList *  threadList)

Destroy a thread list

Parameters:
threadListThe thread list in question
CgThreadList* cg_threadlist_new ( )

Create a new thread list

Returns:
Thread list
BOOL cg_threadlist_start ( CgThreadList *  threadList)

Start all threads in the thread list

Parameters:
threadListThe thread list in question
BOOL cg_threadlist_stop ( CgThreadList *  threadList)

Stop all threads in the thread list

Parameters:
threadListThe thread list in question