@@ -510,7 +510,7 @@ invoke_thread (void *arg)
510510 while (single_h -> state != RUNNING ) {
511511 g_cond_wait (& single_h -> cond , & single_h -> mutex );
512512 if (single_h -> state == JOIN_REQUESTED )
513- goto exit ;
513+ goto exit_thread ;
514514 }
515515
516516 input = single_h -> input ;
@@ -526,34 +526,34 @@ invoke_thread (void *arg)
526526 /* Clear input data after invoke is done. */
527527 ml_tensors_data_destroy (input );
528528 single_h -> invoking = FALSE;
529+ single_h -> status = status ;
529530
530531 if (status != ML_ERROR_NONE || single_h -> state == JOIN_REQUESTED ) {
532+ /* If error occurred or join requested during invocation */
531533 if (alloc_output ) {
532534 single_h -> destroy_data_list =
533535 g_list_remove (single_h -> destroy_data_list , output );
534536 ml_tensors_data_destroy (output );
535537 }
536-
538+ /* If join requested, exit immediately without broadcast */
537539 if (single_h -> state == JOIN_REQUESTED )
538- goto exit ;
539- goto wait_for_next ;
540+ goto exit_thread ;
541+ } else {
542+ /* Process output data on success */
543+ if (alloc_output )
544+ __process_output (single_h , output );
540545 }
541546
542- if (alloc_output )
543- __process_output (single_h , output );
544-
545- /** loop over to wait for the next element */
546- wait_for_next :
547- single_h -> status = status ;
547+ /*Reset state and notify */
548548 if (single_h -> state == RUNNING )
549549 single_h -> state = IDLE ;
550+
550551 g_cond_broadcast (& single_h -> cond );
551552 }
552553
553- exit :
554- /* Do not set IDLE if JOIN_REQUESTED */
554+ exit_thread :
555+ /* Cleanup resources on exit */
555556 if (single_h -> state == JOIN_REQUESTED ) {
556- /* Release input and output data */
557557 if (single_h -> input )
558558 ml_tensors_data_destroy (single_h -> input );
559559
@@ -562,10 +562,11 @@ invoke_thread (void *arg)
562562 g_list_remove (single_h -> destroy_data_list , single_h -> output );
563563 ml_tensors_data_destroy (single_h -> output );
564564 }
565-
566565 single_h -> input = single_h -> output = NULL ;
567- } else if (single_h -> state == RUNNING )
566+ } else if (single_h -> state == RUNNING ) {
568567 single_h -> state = IDLE ;
568+ }
569+
569570 g_mutex_unlock (& single_h -> mutex );
570571 return NULL ;
571572}
0 commit comments