mirror of
https://github.com/lexborisov/Modest
synced 2024-11-25 07:09:35 +03:00
Fixed problem with thread infiniti wait
This commit is contained in:
parent
e55f360724
commit
3228a2df9e
@ -109,7 +109,7 @@ mythread_id_t myhread_increase_id_by_entry_id(mythread_t* mythread, mythread_id_
|
||||
mystatus_t mythread_join(mythread_t *mythread, mythread_callback_before_entry_join_f before_join, void* ctx);
|
||||
mystatus_t mythread_quit(mythread_t *mythread, mythread_callback_before_entry_join_f before_join, void* ctx);
|
||||
mystatus_t mythread_stop(mythread_t *mythread);
|
||||
mystatus_t mythread_resume(mythread_t *mythread);
|
||||
mystatus_t mythread_resume(mythread_t *mythread, mythread_thread_opt_t send_opt);
|
||||
mystatus_t mythread_suspend(mythread_t *mythread);
|
||||
mystatus_t mythread_check_status(mythread_t *mythread);
|
||||
|
||||
@ -122,7 +122,7 @@ mystatus_t myhread_entry_create(mythread_t *mythread, mythread_process_f process
|
||||
mystatus_t mythread_entry_join(mythread_entry_t* entry, mythread_callback_before_entry_join_f before_join, void* ctx);
|
||||
mystatus_t mythread_entry_quit(mythread_entry_t* entry, mythread_callback_before_entry_join_f before_join, void* ctx);
|
||||
mystatus_t mythread_entry_stop(mythread_entry_t* entry);
|
||||
mystatus_t mythread_entry_resume(mythread_entry_t* entry);
|
||||
mystatus_t mythread_entry_resume(mythread_entry_t* entry, mythread_thread_opt_t send_opt);
|
||||
mystatus_t mythread_entry_suspend(mythread_entry_t* entry);
|
||||
mystatus_t mythread_entry_status(mythread_entry_t* entry);
|
||||
mythread_t * mythread_entry_mythread(mythread_entry_t* entry);
|
||||
|
@ -97,15 +97,15 @@ modest_finder_thread_t * modest_finder_thread_destroy(modest_finder_thread_t* fi
|
||||
if(finder_thread == NULL)
|
||||
return NULL;
|
||||
|
||||
finder_thread->entry_obj = mcobject_async_destroy(finder_thread->entry_obj, true);
|
||||
finder_thread->declaration_obj = mcobject_async_destroy(finder_thread->declaration_obj, true);
|
||||
|
||||
#ifndef MyCORE_BUILD_WITHOUT_THREADS
|
||||
if(finder_thread->thread) {
|
||||
finder_thread->thread = mythread_destroy(finder_thread->thread, mythread_callback_quit, NULL, true);
|
||||
}
|
||||
#endif
|
||||
|
||||
finder_thread->entry_obj = mcobject_async_destroy(finder_thread->entry_obj, true);
|
||||
finder_thread->declaration_obj = mcobject_async_destroy(finder_thread->declaration_obj, true);
|
||||
|
||||
if(finder_thread->context_list) {
|
||||
mycore_free(finder_thread->context_list);
|
||||
|
||||
@ -143,7 +143,7 @@ mystatus_t modest_finder_thread_process(modest_t* modest, modest_finder_thread_t
|
||||
if(finder_thread->finder == NULL)
|
||||
return MODEST_STATUS_ERROR;
|
||||
|
||||
mythread_resume(finder_thread->thread);
|
||||
mythread_resume(finder_thread->thread, MyTHREAD_OPT_UNDEF);
|
||||
modest_finder_thread_wait_for_all_done(finder_thread);
|
||||
|
||||
/* calc result */
|
||||
@ -399,8 +399,6 @@ void modest_finder_thread_stream(mythread_id_t thread_id, void* arg)
|
||||
|
||||
selector_list = selector_list->next;
|
||||
}
|
||||
|
||||
ctx->opt = MyTHREAD_OPT_STOP|MyTHREAD_OPT_DONE;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -64,7 +64,7 @@ mythread_t * mythread_destroy(mythread_t *mythread, mythread_callback_before_ent
|
||||
return NULL;
|
||||
|
||||
if(mythread->entries) {
|
||||
mythread_resume(mythread);
|
||||
mythread_resume(mythread, MyTHREAD_OPT_QUIT);
|
||||
mythread_quit(mythread, before_join, ctx);
|
||||
mycore_free(mythread->entries);
|
||||
}
|
||||
@ -194,19 +194,19 @@ mystatus_t mythread_suspend(mythread_t *mythread)
|
||||
return MyCORE_STATUS_OK;
|
||||
}
|
||||
|
||||
mystatus_t mythread_resume(mythread_t *mythread)
|
||||
mystatus_t mythread_resume(mythread_t *mythread, mythread_thread_opt_t send_opt)
|
||||
{
|
||||
if(mythread->opt & MyTHREAD_OPT_WAIT) {
|
||||
mythread_option_set(mythread, MyTHREAD_OPT_UNDEF);
|
||||
mythread_option_set(mythread, send_opt);
|
||||
return MyCORE_STATUS_OK;
|
||||
}
|
||||
|
||||
mythread_option_set(mythread, MyTHREAD_OPT_UNDEF);
|
||||
mythread_option_set(mythread, send_opt);
|
||||
|
||||
for (size_t i = 0; i < mythread->entries_length; i++)
|
||||
{
|
||||
if(mythread->entries[i].context.opt & MyTHREAD_OPT_STOP) {
|
||||
mythread->entries[i].context.opt = MyTHREAD_OPT_UNDEF;
|
||||
mythread->entries[i].context.opt = send_opt;
|
||||
|
||||
if(mythread_mutex_post(mythread, mythread->entries[i].context.mutex))
|
||||
return MyCORE_STATUS_ERROR;
|
||||
@ -293,19 +293,19 @@ mystatus_t mythread_entry_suspend(mythread_entry_t* entry)
|
||||
return MyCORE_STATUS_OK;
|
||||
}
|
||||
|
||||
mystatus_t mythread_entry_resume(mythread_entry_t* entry)
|
||||
mystatus_t mythread_entry_resume(mythread_entry_t* entry, mythread_thread_opt_t send_opt)
|
||||
{
|
||||
if(entry->context.opt & MyTHREAD_OPT_WAIT) {
|
||||
entry->context.opt = MyTHREAD_OPT_UNDEF;
|
||||
entry->context.opt = send_opt;
|
||||
}
|
||||
else if(entry->context.opt & MyTHREAD_OPT_STOP) {
|
||||
entry->context.opt = MyTHREAD_OPT_UNDEF;
|
||||
entry->context.opt = send_opt;
|
||||
|
||||
if(mythread_mutex_post(entry->context.mythread, entry->context.mutex))
|
||||
return MyCORE_STATUS_ERROR;
|
||||
}
|
||||
else
|
||||
entry->context.opt = MyTHREAD_OPT_UNDEF;
|
||||
entry->context.opt = send_opt;
|
||||
|
||||
return MyCORE_STATUS_OK;
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ mythread_id_t myhread_increase_id_by_entry_id(mythread_t* mythread, mythread_id_
|
||||
mystatus_t mythread_join(mythread_t *mythread, mythread_callback_before_entry_join_f before_join, void* ctx);
|
||||
mystatus_t mythread_quit(mythread_t *mythread, mythread_callback_before_entry_join_f before_join, void* ctx);
|
||||
mystatus_t mythread_stop(mythread_t *mythread);
|
||||
mystatus_t mythread_resume(mythread_t *mythread);
|
||||
mystatus_t mythread_resume(mythread_t *mythread, mythread_thread_opt_t send_opt);
|
||||
mystatus_t mythread_suspend(mythread_t *mythread);
|
||||
mystatus_t mythread_check_status(mythread_t *mythread);
|
||||
|
||||
@ -122,7 +122,7 @@ mystatus_t myhread_entry_create(mythread_t *mythread, mythread_process_f process
|
||||
mystatus_t mythread_entry_join(mythread_entry_t* entry, mythread_callback_before_entry_join_f before_join, void* ctx);
|
||||
mystatus_t mythread_entry_quit(mythread_entry_t* entry, mythread_callback_before_entry_join_f before_join, void* ctx);
|
||||
mystatus_t mythread_entry_stop(mythread_entry_t* entry);
|
||||
mystatus_t mythread_entry_resume(mythread_entry_t* entry);
|
||||
mystatus_t mythread_entry_resume(mythread_entry_t* entry, mythread_thread_opt_t send_opt);
|
||||
mystatus_t mythread_entry_suspend(mythread_entry_t* entry);
|
||||
mystatus_t mythread_entry_status(mythread_entry_t* entry);
|
||||
mythread_t * mythread_entry_mythread(mythread_entry_t* entry);
|
||||
|
@ -375,7 +375,7 @@ mythread_queue_list_entry_t * mythread_queue_list_entry_push(mythread_t** mythre
|
||||
|
||||
for(size_t i = 0; i < list_size; i++)
|
||||
if(mythread_list[i])
|
||||
mythread_resume(mythread_list[i]);
|
||||
mythread_resume(mythread_list[i], MyTHREAD_OPT_UNDEF);
|
||||
|
||||
return entry;
|
||||
}
|
||||
@ -405,7 +405,7 @@ mythread_queue_list_entry_t * mythread_queue_list_entry_delete(mythread_t** myth
|
||||
|
||||
for(size_t i = 0; i < list_size; i++)
|
||||
if(mythread_list[i])
|
||||
mythread_resume(mythread_list[i]);
|
||||
mythread_resume(mythread_list[i], MyTHREAD_OPT_UNDEF);
|
||||
|
||||
if(destroy_queue && entry->queue)
|
||||
mythread_queue_destroy(entry->queue);
|
||||
@ -621,33 +621,31 @@ void * mythread_function(void *arg)
|
||||
mythread_mutex_wait(mythread, ctx->mutex);
|
||||
|
||||
do {
|
||||
if(mythread->opt & MyTHREAD_OPT_STOP || ctx->opt & MyTHREAD_OPT_STOP)
|
||||
{
|
||||
ctx->opt = MyTHREAD_OPT_DONE|MyTHREAD_OPT_STOP;
|
||||
ctx->func(ctx->id, ctx);
|
||||
|
||||
ctx->opt |= MyTHREAD_OPT_DONE;
|
||||
|
||||
if(ctx->opt & MyTHREAD_OPT_WAIT) {
|
||||
while (ctx->opt & MyTHREAD_OPT_WAIT) {
|
||||
mythread_nanosleep_sleep(ctx->timespec);
|
||||
}
|
||||
}
|
||||
else {
|
||||
ctx->opt |= MyTHREAD_OPT_STOP;
|
||||
mythread_mutex_wait(mythread, ctx->mutex);
|
||||
}
|
||||
|
||||
if(mythread->opt & MyTHREAD_OPT_QUIT || ctx->opt & MyTHREAD_OPT_QUIT)
|
||||
{
|
||||
mythread_mutex_close(mythread, ctx->mutex);
|
||||
mythread_nanosleep_destroy(ctx->timespec);
|
||||
|
||||
ctx->opt = MyTHREAD_OPT_DONE|MyTHREAD_OPT_QUIT;
|
||||
ctx->opt = MyTHREAD_OPT_QUIT;
|
||||
break;
|
||||
}
|
||||
|
||||
ctx->opt = MyTHREAD_OPT_UNDEF;
|
||||
}
|
||||
else if(mythread->opt & MyTHREAD_OPT_QUIT || ctx->opt & MyTHREAD_OPT_QUIT)
|
||||
{
|
||||
mythread_mutex_close(mythread, ctx->mutex);
|
||||
mythread_nanosleep_destroy(ctx->timespec);
|
||||
|
||||
ctx->opt = MyTHREAD_OPT_DONE|MyTHREAD_OPT_QUIT;
|
||||
break;
|
||||
}
|
||||
|
||||
ctx->func(ctx->id, ctx);
|
||||
}
|
||||
while(1);
|
||||
|
||||
return NULL;
|
||||
|
@ -253,10 +253,10 @@ void myhtml_tokenizer_post(myhtml_tree_t* tree)
|
||||
{
|
||||
#ifndef MyCORE_BUILD_WITHOUT_THREADS
|
||||
if(tree->myhtml->thread_stream)
|
||||
mythread_resume(tree->myhtml->thread_stream);
|
||||
mythread_resume(tree->myhtml->thread_stream, MyTHREAD_OPT_UNDEF);
|
||||
|
||||
if(tree->myhtml->thread_batch)
|
||||
mythread_resume(tree->myhtml->thread_batch);
|
||||
mythread_resume(tree->myhtml->thread_batch, MyTHREAD_OPT_UNDEF);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user