Update documentation.
This commit is contained in:
parent
5dfac5104b
commit
f8f3145678
Binary file not shown.
|
@ -74,10 +74,10 @@ TSK_BEGIN_DECLS
|
|||
#define tsk_fsm_action_any -0xFFFF
|
||||
|
||||
/**@ingroup tsk_fsm_group
|
||||
* @def tsk_fsm_state_id
|
||||
* @def tsk_fsm_state_id_t
|
||||
*/
|
||||
/**@ingroup tsk_fsm_group
|
||||
* @def tsk_fsm_action_id
|
||||
* @def tsk_fsm_action_id_t
|
||||
*/
|
||||
/**@ingroup tsk_fsm_group
|
||||
* @def tsk_fsm_cond
|
||||
|
|
|
@ -63,7 +63,7 @@ void tsk_list_remove_item(tsk_list_t* list, tsk_list_item_t* item)
|
|||
* @param tskobj Any valid object(declared using @ref TSK_DECLARE_OBJECT) to remove.
|
||||
* @retval The item.
|
||||
*/
|
||||
tsk_list_item_t* tsk_list_pop_item_by_data(tsk_list_t* list, const void * tskobj)
|
||||
tsk_list_item_t* tsk_list_pop_item_by_data(tsk_list_t* list, const tsk_object_t * tskobj)
|
||||
{
|
||||
if(list)
|
||||
{
|
||||
|
@ -112,7 +112,7 @@ tsk_list_item_t* tsk_list_pop_item_by_data(tsk_list_t* list, const void * tskobj
|
|||
* @param list The list from which to remove the object.
|
||||
* @param tskobj Any valid object(declared using @ref TSK_DECLARE_OBJECT) to remove.
|
||||
*/
|
||||
void tsk_list_remove_item_by_data(tsk_list_t* list, const void * tskobj)
|
||||
void tsk_list_remove_item_by_data(tsk_list_t* list, const tsk_object_t * tskobj)
|
||||
{
|
||||
tsk_list_item_t* item;
|
||||
if((item = tsk_list_pop_item_by_data(list, tskobj))){
|
||||
|
@ -177,7 +177,7 @@ tsk_list_item_t* tsk_list_pop_item_by_pred(tsk_list_t* list, tsk_list_func_predi
|
|||
* @param predicate The predicate function used to match the item.
|
||||
* @param data Arbitrary data to pass to the predicate function.
|
||||
*/
|
||||
void tsk_list_remove_item_by_pred(tsk_list_t* list, tsk_list_func_predicate predicate, const void * data)
|
||||
void tsk_list_remove_item_by_pred(tsk_list_t* list, tsk_list_func_predicate predicate, const tsk_object_t * data)
|
||||
{
|
||||
tsk_list_item_t* item;
|
||||
if((item = tsk_list_pop_item_by_pred(list, predicate, data))){
|
||||
|
@ -360,7 +360,7 @@ void tsk_list_push_filtered_data(tsk_list_t* list, void** data, int ascending)
|
|||
* @param tskobj The @a object to find.
|
||||
* @retval A @ref tsk_list_item_t item if found and NULL otherwize.
|
||||
*/
|
||||
const tsk_list_item_t* tsk_list_find_item_by_data(const tsk_list_t* list, const void * tskobj)
|
||||
const tsk_list_item_t* tsk_list_find_item_by_data(const tsk_list_t* list, const tsk_object_t * tskobj)
|
||||
{
|
||||
if(list && tskobj)
|
||||
{
|
||||
|
@ -383,7 +383,7 @@ const tsk_list_item_t* tsk_list_find_item_by_data(const tsk_list_t* list, const
|
|||
* @param data data passed to the predicate function for comparaison
|
||||
* @retval the item which match the criteria and NULL otherwise
|
||||
*/
|
||||
const tsk_list_item_t* tsk_list_find_item_by_pred(const tsk_list_t* list, tsk_list_func_predicate predicate, const void * data)
|
||||
const tsk_list_item_t* tsk_list_find_item_by_pred(const tsk_list_t* list, tsk_list_func_predicate predicate, const tsk_object_t * data)
|
||||
{
|
||||
if(predicate)
|
||||
{
|
||||
|
|
|
@ -96,10 +96,10 @@ typedef int (*tsk_list_func_predicate)(const tsk_list_item_t* item, const void*
|
|||
#define tsk_list_foreach(item, list) for(item = list?list->head:0; item; item= item->next)
|
||||
|
||||
TINYSAK_API void tsk_list_remove_item(tsk_list_t* list, tsk_list_item_t* item);
|
||||
TINYSAK_API tsk_list_item_t* tsk_list_pop_item_by_data(tsk_list_t* list, const void * tskobj);
|
||||
TINYSAK_API void tsk_list_remove_item_by_data(tsk_list_t* list, const void * tskobj);
|
||||
TINYSAK_API void tsk_list_remove_item_by_pred(tsk_list_t* list, tsk_list_func_predicate predicate, const void * data);
|
||||
TINYSAK_API tsk_list_item_t* tsk_list_pop_item_by_pred(tsk_list_t* list, tsk_list_func_predicate predicate, const void * data);
|
||||
TINYSAK_API tsk_list_item_t* tsk_list_pop_item_by_data(tsk_list_t* list, const tsk_object_t * tskobj);
|
||||
TINYSAK_API void tsk_list_remove_item_by_data(tsk_list_t* list, const tsk_object_t * tskobj);
|
||||
TINYSAK_API void tsk_list_remove_item_by_pred(tsk_list_t* list, tsk_list_func_predicate predicate, const tsk_object_t * data);
|
||||
TINYSAK_API tsk_list_item_t* tsk_list_pop_item_by_pred(tsk_list_t* list, tsk_list_func_predicate predicate, const tsk_object_t * data);
|
||||
TINYSAK_API void tsk_list_clear_items(tsk_list_t* list);
|
||||
|
||||
TINYSAK_API tsk_list_item_t* tsk_list_pop_first_item(tsk_list_t* list);
|
||||
|
@ -121,7 +121,7 @@ TINYSAK_API void tsk_list_push_filtered_data(tsk_list_t* list, void** data, int
|
|||
#define tsk_list_push_ascending_data(list, data) tsk_list_push_filtered_data(list, data, 1)
|
||||
#define tsk_list_push_descending_data(list, data) tsk_list_push_filtered_data(list, data, 0)
|
||||
|
||||
TINYSAK_API const tsk_list_item_t* tsk_list_find_item_by_data(const tsk_list_t* list, const void * tskobj);
|
||||
TINYSAK_API const tsk_list_item_t* tsk_list_find_item_by_data(const tsk_list_t* list, const tsk_object_t * tskobj);
|
||||
TINYSAK_API const tsk_list_item_t* tsk_list_find_item_by_pred(const tsk_list_t* list, tsk_list_func_predicate predicate, const void * data);
|
||||
|
||||
TINYSAK_GEXTERN const void *tsk_list_def_t;
|
||||
|
|
|
@ -43,12 +43,12 @@ TSK_BEGIN_DECLS
|
|||
typedef void tsk_object_t;
|
||||
|
||||
/**@ingroup tsk_object_group
|
||||
* Safely free any object created using @ref tsk_object_new and declared using @ref TSK_DECLARE_OBJECT. If the reference count of the object was equal to 1 then this
|
||||
* Safely free any well-defined object. If the reference count of the object was equal to 1 then this
|
||||
* object will be freed otherwise the refrence counter will be decremented.
|
||||
* In all case this operation will set the pointer (the object itself) to NULL.
|
||||
* @param self The object to free or unref.
|
||||
**/
|
||||
#define TSK_OBJECT_SAFE_FREE(self) tsk_object_unref(self), self = 0
|
||||
#define TSK_OBJECT_SAFE_FREE(self) tsk_object_unref(self), self = tsk_null
|
||||
|
||||
/**@ingroup tsk_object_group
|
||||
* tag a structure as an object. If this macro is used then you MUST
|
||||
|
|
|
@ -88,7 +88,7 @@ typedef char tsk_sha1digest_t[TSK_SHA1_DIGEST_SIZE]; /**< SHA-1 digest bytes. */
|
|||
|
||||
/**@ingroup tsk_sha1_group
|
||||
* This structure will hold context information for the SHA-1
|
||||
* hashing operation
|
||||
* hashing SSESSION
|
||||
*/
|
||||
typedef struct tsk_sha1context_s
|
||||
{
|
||||
|
|
|
@ -46,11 +46,7 @@
|
|||
|
||||
/**
|
||||
* @struct tsk_timer_s
|
||||
*
|
||||
* @brief Timer.
|
||||
*
|
||||
* @author Mamadou
|
||||
* @date 12/20/2009
|
||||
**/
|
||||
typedef struct tsk_timer_s
|
||||
{
|
||||
|
@ -70,15 +66,11 @@ typedef tsk_list_t tsk_timers_L_t; /**< List of @ref tsk_timer_t elements. */
|
|||
* @struct tsk_timer_manager_s
|
||||
*
|
||||
* @brief Timer manager.
|
||||
*
|
||||
* @author Mamadou
|
||||
* @date 12/20/2009
|
||||
**/
|
||||
typedef struct tsk_timer_manager_s
|
||||
{
|
||||
TSK_DECLARE_RUNNABLE;
|
||||
|
||||
unsigned active:1;
|
||||
void* mainThreadId[1];
|
||||
tsk_condwait_handle_t *condwait;
|
||||
tsk_mutex_handle_t *mutex;
|
||||
|
@ -96,7 +88,7 @@ static void __tsk_timer_manager_raise(tsk_timer_t *timer);
|
|||
static void *run(void* self);
|
||||
|
||||
/**@ingroup tsk_timer_group
|
||||
* Start the timer manager.
|
||||
* Starts the timer manager.
|
||||
*/
|
||||
int tsk_timer_manager_start(tsk_timer_manager_handle_t *self)
|
||||
{
|
||||
|
@ -105,34 +97,14 @@ int tsk_timer_manager_start(tsk_timer_manager_handle_t *self)
|
|||
if(manager && !TSK_RUNNABLE(manager)->running)
|
||||
{
|
||||
TSK_RUNNABLE(manager)->run = run;
|
||||
if(err = tsk_runnable_start(TSK_RUNNABLE(manager), tsk_timer_def_t))
|
||||
{
|
||||
TSK_OBJECT_SAFE_FREE(manager);
|
||||
return err;
|
||||
}
|
||||
|
||||
if(err = tsk_thread_create(&(manager->mainThreadId[0]), __tsk_timer_manager_mainthread, manager))
|
||||
{
|
||||
TSK_OBJECT_SAFE_FREE(manager);
|
||||
|
||||
TSK_DEBUG_FATAL("Failed to start timer manager: %d\n", err);
|
||||
if(err = tsk_runnable_start(TSK_RUNNABLE(manager), tsk_timer_def_t)){
|
||||
//TSK_OBJECT_SAFE_FREE(manager);
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
/**@ingroup tsk_timer_group
|
||||
*/
|
||||
int tsk_timer_manager_isready(tsk_timer_manager_handle_t *self)
|
||||
{
|
||||
tsk_timer_manager_t *manager = self;
|
||||
if(manager)
|
||||
{
|
||||
return (TSK_RUNNABLE(manager)->running && manager->active);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(DEBUG) || defined(_DEBUG) || !defined(NDEBUG)
|
||||
/**@ingroup tsk_timer_group
|
||||
|
@ -147,8 +119,7 @@ void tsk_timer_manager_debug(tsk_timer_manager_handle_t *self)
|
|||
|
||||
tsk_mutex_lock(manager->mutex);
|
||||
|
||||
tsk_list_foreach(item, manager->timers)
|
||||
{
|
||||
tsk_list_foreach(item, manager->timers){
|
||||
tsk_timer_t* timer = item->data;
|
||||
TSK_DEBUG_INFO("timer [%d]- %llu, %llu", timer->id, timer->timeout, tsk_time_epoch());
|
||||
}
|
||||
|
@ -185,8 +156,7 @@ tsk_timer_id_t tsk_timer_manager_schedule(tsk_timer_manager_handle_t *self, uint
|
|||
tsk_timer_id_t timer_id = TSK_INVALID_TIMER_ID;
|
||||
tsk_timer_manager_t *manager = self;
|
||||
|
||||
if(manager && TSK_RUNNABLE(manager)->running)
|
||||
{
|
||||
if(manager && TSK_RUNNABLE(manager)->running){
|
||||
tsk_timer_t *timer;
|
||||
|
||||
timer = TSK_TIMER_CREATE(timeout, callback, arg);
|
||||
|
@ -240,16 +210,23 @@ int tsk_timer_manager_cancel(tsk_timer_manager_handle_t *self, tsk_timer_id_t id
|
|||
|
||||
static void *run(void* self)
|
||||
{
|
||||
int ret;
|
||||
tsk_list_item_t *curr;
|
||||
tsk_timer_manager_t *manager = self;
|
||||
|
||||
TSK_RUNNABLE(manager)->running = tsk_true; // VERY IMPORTANT --> needed by the main thread
|
||||
|
||||
/* create main thread */
|
||||
if((ret = tsk_thread_create(&(manager->mainThreadId[0]), __tsk_timer_manager_mainthread, manager))){
|
||||
TSK_DEBUG_FATAL("Failed to create mainthread: %d\n", ret);
|
||||
return tsk_null;
|
||||
}
|
||||
|
||||
TSK_RUNNABLE_RUN_BEGIN(manager);
|
||||
|
||||
if(curr = TSK_RUNNABLE_POP_FIRST(manager))
|
||||
{
|
||||
if(curr = TSK_RUNNABLE_POP_FIRST(manager)){
|
||||
tsk_timer_t *timer = (tsk_timer_t *)curr->data;
|
||||
if(timer->callback)
|
||||
{
|
||||
if(timer->callback){
|
||||
timer->callback(timer->arg, timer->id);
|
||||
}
|
||||
tsk_object_unref(curr);
|
||||
|
@ -257,14 +234,13 @@ static void *run(void* self)
|
|||
|
||||
TSK_RUNNABLE_RUN_END(manager);
|
||||
|
||||
return 0;
|
||||
return tsk_null;
|
||||
}
|
||||
|
||||
static int __tsk_pred_find_timer_by_id(const tsk_list_item_t *item, const void *id)
|
||||
{
|
||||
tsk_timer_t *timer;
|
||||
if(item && item->data)
|
||||
{
|
||||
if(item && item->data){
|
||||
timer = item->data;
|
||||
return (int)(timer->id - *((tsk_timer_id_t*)id));
|
||||
}
|
||||
|
@ -273,20 +249,19 @@ static int __tsk_pred_find_timer_by_id(const tsk_list_item_t *item, const void *
|
|||
|
||||
static void *__tsk_timer_manager_mainthread(void *param)
|
||||
{
|
||||
int ret;
|
||||
tsk_timer_t *curr;
|
||||
uint64_t epoch;
|
||||
tsk_timer_manager_t *manager = param;
|
||||
|
||||
TSK_DEBUG_INFO("TIMER MANAGER -- START");
|
||||
|
||||
manager->active = 1;
|
||||
while(TSK_RUNNABLE(manager)->running)
|
||||
{
|
||||
tsk_semaphore_decrement(manager->sem);
|
||||
|
||||
peek_first:
|
||||
if(!TSK_RUNNABLE(manager)->running)
|
||||
{
|
||||
if(!TSK_RUNNABLE(manager)->running){
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -294,39 +269,35 @@ peek_first:
|
|||
curr = TSK_TIMER_GET_FIRST();
|
||||
tsk_mutex_unlock(manager->mutex);
|
||||
|
||||
if(curr && !curr->canceled)
|
||||
{
|
||||
if(curr && !curr->canceled) {
|
||||
epoch = tsk_time_epoch();
|
||||
if(epoch >= curr->timeout)
|
||||
{
|
||||
if(epoch >= curr->timeout){
|
||||
tsk_timer_t *timer = tsk_object_ref(curr);
|
||||
//TSK_DEBUG_INFO("Timer raise %llu", timer->id);
|
||||
|
||||
tsk_mutex_lock(manager->mutex);
|
||||
TSK_RUNNABLE_ENQUEUE_OBJECT(TSK_RUNNABLE(manager), timer);
|
||||
tsk_list_remove_item_by_data(manager->timers, curr);
|
||||
tsk_mutex_unlock(manager->mutex);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(tsk_condwait_timedwait(manager->condwait, (curr->timeout - epoch)))
|
||||
{
|
||||
else{
|
||||
if((ret = tsk_condwait_timedwait(manager->condwait, (curr->timeout - epoch)))){
|
||||
TSK_DEBUG_ERROR("CONWAIT for timer manager failed [%d]", ret);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
else{
|
||||
goto peek_first;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(curr)
|
||||
{
|
||||
else if(curr){
|
||||
tsk_mutex_lock(manager->mutex);
|
||||
//TSK_DEBUG_INFO("Timer canceled %llu", curr->id);
|
||||
tsk_list_remove_item_by_data(manager->timers, curr);
|
||||
tsk_mutex_unlock(manager->mutex);
|
||||
}
|
||||
}
|
||||
|
||||
manager->active = 0;
|
||||
TSK_DEBUG_INFO("TIMER MANAGER -- STOP");
|
||||
|
||||
return 0;
|
||||
|
@ -354,8 +325,7 @@ peek_first:
|
|||
static void* tsk_timer_manager_create(void * self, va_list * app)
|
||||
{
|
||||
tsk_timer_manager_t *manager = self;
|
||||
if(manager)
|
||||
{
|
||||
if(manager){
|
||||
manager->timers = TSK_LIST_CREATE();
|
||||
manager->sem = tsk_semaphore_create();
|
||||
manager->condwait = tsk_condwait_create();
|
||||
|
@ -368,8 +338,7 @@ static void* tsk_timer_manager_destroy(void * self)
|
|||
{
|
||||
tsk_timer_manager_t *manager = self;
|
||||
|
||||
if(manager)
|
||||
{
|
||||
if(manager){
|
||||
tsk_timer_manager_stop(manager);
|
||||
|
||||
tsk_semaphore_destroy(&manager->sem);
|
||||
|
@ -386,7 +355,7 @@ static const tsk_object_def_t tsk_timer_manager_def_s =
|
|||
sizeof(tsk_timer_manager_t),
|
||||
tsk_timer_manager_create,
|
||||
tsk_timer_manager_destroy,
|
||||
0,
|
||||
tsk_null,
|
||||
};
|
||||
const void * tsk_timer_manager_def_t = &tsk_timer_manager_def_s;
|
||||
|
||||
|
@ -402,8 +371,7 @@ static void* tsk_timer_create(void * self, va_list * app)
|
|||
{
|
||||
static tsk_timer_id_t tsk_unique_timer_id = 1;
|
||||
tsk_timer_t *timer = self;
|
||||
if(timer)
|
||||
{
|
||||
if(timer){
|
||||
timer->id = tsk_unique_timer_id++;
|
||||
timer->timeout = va_arg(*app, uint64_t);
|
||||
timer->callback = va_arg(*app, tsk_timer_callback);
|
||||
|
@ -418,8 +386,7 @@ static void* tsk_timer_destroy(void * self)
|
|||
{
|
||||
tsk_timer_t *timer = self;
|
||||
|
||||
if(timer)
|
||||
{
|
||||
if(timer){
|
||||
}
|
||||
|
||||
return self;
|
||||
|
@ -430,8 +397,7 @@ static int tsk_timer_cmp(const void *obj1, const void *obj2)
|
|||
const tsk_timer_t *t1 = obj1;
|
||||
const tsk_timer_t *t2 = obj2;
|
||||
|
||||
if(t1 && t2)
|
||||
{
|
||||
if(t1 && t2){
|
||||
return (int)(t1->timeout - t2->timeout);
|
||||
}
|
||||
else if(!t1 && !t2) return 0;
|
||||
|
|
|
@ -66,7 +66,6 @@ typedef uint64_t tsk_timer_id_t;
|
|||
typedef int (*tsk_timer_callback)(const void* arg, tsk_timer_id_t timer_id);
|
||||
|
||||
TINYSAK_API int tsk_timer_manager_start(tsk_timer_manager_handle_t *self);
|
||||
TINYSAK_API int tsk_timer_manager_isready(tsk_timer_manager_handle_t *self);
|
||||
TINYSAK_API int tsk_timer_manager_stop(tsk_timer_manager_handle_t *self);
|
||||
#if defined(DEBUG) || defined(_DEBUG)
|
||||
TINYSAK_API void tsk_timer_manager_debug(tsk_timer_manager_handle_t *self);
|
||||
|
|
|
@ -38,11 +38,12 @@
|
|||
#define RUN_TEST_HEAP 0
|
||||
#define RUN_TEST_STRINGS 0
|
||||
#define RUN_TEST_URL 0
|
||||
#define RUN_TEST_THREADS 1
|
||||
#define RUN_TEST_MUTEX 0
|
||||
#define RUN_TEST_CONDWAIT 0
|
||||
#define RUN_TEST_SEMAPHORE 0 /* FIXME: android */
|
||||
#define RUN_TEST_SAFEOBJECT 0
|
||||
#define RUN_TEST_OBJECT 1
|
||||
#define RUN_TEST_OBJECT 0
|
||||
#define RUN_TEST_PARAMS 0
|
||||
#define RUN_TEST_TIMER 0
|
||||
#define RUN_TEST_RUNNABLE 0
|
||||
|
@ -69,6 +70,10 @@
|
|||
#include "test_url.h"
|
||||
#endif
|
||||
|
||||
#if RUN_TEST_THREADS || RUN_TEST_ALL
|
||||
#include "test_threads.h"
|
||||
#endif
|
||||
|
||||
#if RUN_TEST_MUTEX || RUN_TEST_ALL
|
||||
#include "test_mutex.h"
|
||||
#endif
|
||||
|
@ -167,6 +172,12 @@ int main()
|
|||
printf("\n\n");
|
||||
#endif
|
||||
|
||||
#if RUN_TEST_THREADS || RUN_TEST_ALL
|
||||
/* threads */
|
||||
test_threads();
|
||||
printf("\n\n");
|
||||
#endif
|
||||
|
||||
#if RUN_TEST_MUTEX || RUN_TEST_ALL
|
||||
/* mutex */
|
||||
test_mutex();
|
||||
|
|
|
@ -427,6 +427,10 @@
|
|||
RelativePath=".\test_strings.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\test_threads.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\test_timer.h"
|
||||
>
|
||||
|
|
|
@ -20,13 +20,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/**@file tsk_mutex.h
|
||||
* @brief Pthread mutex.
|
||||
*
|
||||
* @author Mamadou Diop <diopmamadou(at)yahoo.fr>
|
||||
*
|
||||
* @date Created: Sat Nov 8 16:54:58 2009 mdiop
|
||||
*/
|
||||
|
||||
#ifndef _TEST_MUTEX_H_
|
||||
#define _TEST_MUTEX_H_
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ typedef struct person_s
|
|||
TSK_DECLARE_OBJECT; // Mandatory
|
||||
|
||||
char* name;
|
||||
person_t* mother;
|
||||
struct person_s* mother;
|
||||
}
|
||||
person_t;
|
||||
|
||||
|
@ -46,14 +46,14 @@ static void* person_create(tsk_object_t * self, va_list * app)
|
|||
{
|
||||
person_t *person = self;
|
||||
if(person){
|
||||
TSK_FREE(person->firstName);
|
||||
TSK_FREE(person->lastName);
|
||||
TSK_FREE(person->name);
|
||||
tsk_object_unref(person->mother);
|
||||
}
|
||||
return self;
|
||||
return self; // return
|
||||
}
|
||||
|
||||
// comparator
|
||||
static int person_cmp(const tsk_object_t *object1, const tsk_object_t *object1)
|
||||
static int person_cmp(const tsk_object_t *object1, const tsk_object_t *object2)
|
||||
{
|
||||
const person_t *person1 = object1;
|
||||
const person_t *person2 = object2;
|
||||
|
@ -73,29 +73,26 @@ static void* person_create(tsk_object_t * self, va_list * app)
|
|||
}
|
||||
|
||||
//(Object defnition)
|
||||
static const tsk_object_def_t person_def_s =
|
||||
static const tsk_object_def_t person_def_t =
|
||||
{
|
||||
sizeof(person_t),
|
||||
person_create,
|
||||
person_destroy,
|
||||
person_cmp,
|
||||
}person_def_t;
|
||||
person_cmp
|
||||
};
|
||||
|
||||
// create a person
|
||||
#define PERSON_CREATE(name) tsk_object_new(&person_def_t, (const char*)name)
|
||||
|
||||
/* test object */
|
||||
void test_object()
|
||||
{
|
||||
tsk_string_t *a = tsk_object_new(tsk_string_def_t, "first string");
|
||||
tsk_string_t *b = tsk_object_new(tsk_string_def_t, "second string");
|
||||
|
||||
a = tsk_object_ref(a);
|
||||
a = tsk_object_ref(a);
|
||||
|
||||
a = tsk_object_unref(a);
|
||||
a = tsk_object_unref(a);
|
||||
a = tsk_object_unref(a);
|
||||
|
||||
tsk_object_delete(a);
|
||||
tsk_object_delete(b);
|
||||
// create a person: will call the constructor
|
||||
person_t* bob = PERSON_CREATE("bob");
|
||||
// create bob's mother
|
||||
bob->mother = PERSON_CREATE("alice");
|
||||
// delete bob: will delete both bob and bob's mother field by calling their destructors
|
||||
TSK_OBJECT_SAFE_FREE(bob);
|
||||
}
|
||||
|
||||
#endif /* _TEST_OBJECT_H_ */
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright (C) 2009 Mamadou Diop.
|
||||
*
|
||||
* Contact: Mamadou Diop <diopmamadou@yahoo.fr>
|
||||
*
|
||||
* This file is part of Open Source Doubango Framework.
|
||||
*
|
||||
* DOUBANGO is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* DOUBANGO is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with DOUBANGO.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _TEST_THREADS_H_
|
||||
#define _TEST_THREADS_H_
|
||||
|
||||
|
||||
void* MyThreadFunction(void *arg)
|
||||
{
|
||||
printf("arg=%d", *((int*)arg));
|
||||
return tsk_null;
|
||||
}
|
||||
|
||||
void test_threads()
|
||||
{
|
||||
void* tid[1] = {tsk_null}; // thread id
|
||||
int arg = 112; // arg to pass to the function
|
||||
|
||||
printf("test_threads//\n");
|
||||
|
||||
// create the thread
|
||||
tsk_thread_create(&tid[0], MyThreadFunction, &arg);
|
||||
|
||||
// join the thread
|
||||
tsk_thread_join(&(tid[0]));
|
||||
}
|
||||
|
||||
#endif /* _TEST_THREADS_H_ */
|
Loading…
Reference in New Issue