mythread_t * mythread_destroy(mythread_t *mythread, bool self_destroy) { if(mythread == NULL) return NULL; #ifndef MyHTML_BUILD_WITHOUT_THREADS myhtml_thread_attr_destroy(mythread); if(mythread->pth_list) { mythread_resume_all(mythread); mythread_stream_quit_all(mythread); mythread_batch_quit_all(mythread); mythread_wait_all_for_done(mythread); for (size_t i = mythread->pth_list_root; i < mythread->pth_list_length; i++) { myhtml_thread_join(mythread, &mythread->pth_list[i]); } free(mythread->pth_list); mythread->pth_list = NULL; } if(mythread->queue_list) { free(mythread->queue_list); } if(mythread->sem_prefix) { free(mythread->sem_prefix); mythread->sem_prefix = NULL; mythread->sem_prefix_length = 0; } #endif /* MyHTML_BUILD_WITHOUT_THREADS */ if(self_destroy) { free(mythread); return NULL; } return mythread; }
mythread_t * mythread_destroy(mythread_t *mythread, bool self_destroy) { if(mythread == NULL) return NULL; myhtml_thread_attr_destroy(mythread); if(mythread->pth_list) { mythread_resume_all(mythread); mythread_stream_quit_all(mythread); mythread_batch_quit_all(mythread); mythread_wait_all(mythread); for (size_t i = mythread->pth_list_root; i < mythread->pth_list_length; i++) { myhtml_thread_join(mythread, &mythread->pth_list[i]); if(mythread->pth_list[i].data.sem_name) { free(mythread->pth_list[i].data.sem_name); } } free(mythread->pth_list); mythread->pth_list = NULL; } if(mythread->sem_prefix) { free(mythread->sem_prefix); mythread->sem_prefix = NULL; mythread->sem_prefix_length = 0; } if(mythread->queue) mythread_queue_destroy(mythread->queue); if(self_destroy) { free(mythread); return NULL; } return mythread; }