diff --git a/list_t/src/list_t/list_t.c b/list_t/src/list_t/list_t.c index 8ae3e3a..873dc6f 100644 --- a/list_t/src/list_t/list_t.c +++ b/list_t/src/list_t/list_t.c @@ -150,4 +150,6 @@ GEN_LIST_ALL(TYPE_STRING) GEN_LIST_ALL(TYPE_PTR) - +GEN_FUNC_PTR_LIST_FREE(TYPE_PTR){ + free(arg); +} diff --git a/list_t/src/list_t/list_t.h b/list_t/src/list_t/list_t.h index d42572d..7a0faac 100644 --- a/list_t/src/list_t/list_t.h +++ b/list_t/src/list_t/list_t.h @@ -270,11 +270,38 @@ GENERATE_LIST_ALL(TYPE_PTR) }\ +#define GEN_HEAD_PTR_LIST(type)\ + void purge_ptr_type_list_##type(struct main_list_##type *var_list);\ + void free_##type(void *arg);\ + + + +#define GEN_FUNC_PTR_LIST_FREE(type)\ + void purge_ptr_type_list_##type(struct main_list_##type *var_list){\ + struct list_##type *tmp = var_list->begin_list;\ + while(tmp){\ + var_list->current_list = tmp;\ + tmp = tmp->next;\ + free_##type(var_list->current_list->value);\ + free(var_list->current_list);\ + }\ + var_list->begin_list = NULL;\ + var_list->current_list = NULL;\ + var_list->end_list = NULL;\ + var_list->size = 0;\ + var_list->current_index = 0;\ + }\ + void free_##type(void *arg)\ + + +GEN_HEAD_PTR_LIST(TYPE_PTR) + #define LIST_T(type) \ GENERATE_LIST_ALL(type)\ GEN_LIST_ALL(type) + #endif /* __LIST_T_C__H */ diff --git a/y_worker_t/include/y_worker_t/y_worker_t.h b/y_worker_t/include/y_worker_t/y_worker_t.h index 757daa6..fd82fe9 100644 --- a/y_worker_t/include/y_worker_t/y_worker_t.h +++ b/y_worker_t/include/y_worker_t/y_worker_t.h @@ -34,7 +34,7 @@ typedef struct y_worker_t * ptr_y_WORKER_T; //GENERATE_LIST_ALL(y_WORKER_T) GENERATE_LIST_ALL(ptr_y_WORKER_T) -//GENERATE_PTR_type_SIG((ptr_y_WORKER_T) +GEN_HEAD_PTR_LIST(ptr_y_WORKER_T) //ptr_y_WORKER_T create_ptr_y_WORKER_T(int exec, int id); diff --git a/y_worker_t/src/y_worker_t/y_worker_t.c b/y_worker_t/src/y_worker_t/y_worker_t.c index 64705fc..ce7a8b8 100644 --- a/y_worker_t/src/y_worker_t/y_worker_t.c +++ b/y_worker_t/src/y_worker_t/y_worker_t.c @@ -44,7 +44,7 @@ ptr_y_WORKER_T create_ptr_y_WORKER_T(struct main_list_ptr_y_WORKER_T * workers, return pworker; } -void free_ptr_y_WORKER_T(void* p_worker){ +void __free_ptr_y_WORKER_T(void* p_worker){ ptr_y_WORKER_T pworker = (struct y_worker_t*)p_worker; pthread_mutex_destroy(pworker->mut_worker); free(pworker->mut_worker); @@ -55,7 +55,7 @@ void free_ptr_y_WORKER_T(void* p_worker){ free(pworker); } - +/* void purge_list_ptr_y_WORKER_T(struct main_list_ptr_y_WORKER_T *list_workers){ for(move_current_to_begin_list_ptr_y_WORKER_T(list_workers); list_workers->current_list; increment_list_ptr_y_WORKER_T(list_workers)){ free_ptr_y_WORKER_T(list_workers->current_list->value); @@ -69,7 +69,7 @@ void purge_list_TYPE_PTR(struct main_list_TYPE_PTR *list_voids){ free_all_var_list_TYPE_PTR(list_voids); } - +*/ void* execute_work(void* arg){ @@ -122,6 +122,17 @@ int check_worker_status(struct y_worker_t * pworker ){ return ret; } +GEN_FUNC_PTR_LIST_FREE(ptr_y_WORKER_T){ + ptr_y_WORKER_T pworker = (struct y_worker_t*)arg; + pthread_mutex_destroy(pworker->mut_worker); + free(pworker->mut_worker); + pthread_cond_destroy(pworker->cond_worker); + free(pworker->cond_worker); + free(pworker->thread); + free(pworker->arg); + free(pworker); +} + void kill_all_workers ( struct argWorker *argw){ struct main_list_ptr_y_WORKER_T * workers = argw->workers; struct argExecTasQ *argx = argw->argx; @@ -155,10 +166,13 @@ void kill_all_workers ( struct argWorker *argw){ pthread_mutex_destroy(argw->mut_workers); free(argw->mut_workers); - +/* purge_list_TYPE_PTR(argw->list_arg); purge_list_ptr_y_WORKER_T(workers); - +*/ + purge_ptr_type_list_TYPE_PTR(argw->list_arg); + purge_ptr_type_list_ptr_y_WORKER_T(workers); + free_argExecTasQ(argx);