list: add purge ptr type list

This commit is contained in:
2025-06-04 00:09:47 +02:00
parent 8f8a9ff42c
commit 542921f45e
4 changed files with 50 additions and 7 deletions
+3 -1
View File
@@ -150,4 +150,6 @@ GEN_LIST_ALL(TYPE_STRING)
GEN_LIST_ALL(TYPE_PTR) GEN_LIST_ALL(TYPE_PTR)
GEN_FUNC_PTR_LIST_FREE(TYPE_PTR){
free(arg);
}
+27
View File
@@ -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) \ #define LIST_T(type) \
GENERATE_LIST_ALL(type)\ GENERATE_LIST_ALL(type)\
GEN_LIST_ALL(type) GEN_LIST_ALL(type)
#endif /* __LIST_T_C__H */ #endif /* __LIST_T_C__H */
+1 -1
View File
@@ -34,7 +34,7 @@ typedef struct y_worker_t * ptr_y_WORKER_T;
//GENERATE_LIST_ALL(y_WORKER_T) //GENERATE_LIST_ALL(y_WORKER_T)
GENERATE_LIST_ALL(ptr_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); //ptr_y_WORKER_T create_ptr_y_WORKER_T(int exec, int id);
+18 -4
View File
@@ -44,7 +44,7 @@ ptr_y_WORKER_T create_ptr_y_WORKER_T(struct main_list_ptr_y_WORKER_T * workers,
return pworker; 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; ptr_y_WORKER_T pworker = (struct y_worker_t*)p_worker;
pthread_mutex_destroy(pworker->mut_worker); pthread_mutex_destroy(pworker->mut_worker);
free(pworker->mut_worker); free(pworker->mut_worker);
@@ -55,7 +55,7 @@ void free_ptr_y_WORKER_T(void* p_worker){
free(pworker); free(pworker);
} }
/*
void purge_list_ptr_y_WORKER_T(struct main_list_ptr_y_WORKER_T *list_workers){ 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)){ 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); 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); free_all_var_list_TYPE_PTR(list_voids);
} }
*/
void* execute_work(void* arg){ void* execute_work(void* arg){
@@ -122,6 +122,17 @@ int check_worker_status(struct y_worker_t * pworker ){
return ret; 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){ void kill_all_workers ( struct argWorker *argw){
struct main_list_ptr_y_WORKER_T * workers = argw->workers; struct main_list_ptr_y_WORKER_T * workers = argw->workers;
struct argExecTasQ *argx = argw->argx; struct argExecTasQ *argx = argw->argx;
@@ -155,9 +166,12 @@ void kill_all_workers ( struct argWorker *argw){
pthread_mutex_destroy(argw->mut_workers); pthread_mutex_destroy(argw->mut_workers);
free(argw->mut_workers); free(argw->mut_workers);
/*
purge_list_TYPE_PTR(argw->list_arg); purge_list_TYPE_PTR(argw->list_arg);
purge_list_ptr_y_WORKER_T(workers); 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); free_argExecTasQ(argx);