@@ -526,7 +526,7 @@ invoke_thread (void *arg)
526526 while (single_h -> state != RUNNING ) {
527527 g_cond_wait (& single_h -> cond , & single_h -> mutex );
528528 if (single_h -> state == JOIN_REQUESTED )
529- goto exit ;
529+ goto exit_thread ;
530530 }
531531
532532 input = single_h -> input ;
@@ -542,34 +542,34 @@ invoke_thread (void *arg)
542542 /* Clear input data after invoke is done. */
543543 ml_tensors_data_destroy (input );
544544 single_h -> invoking = FALSE;
545+ single_h -> status = status ;
545546
546547 if (status != ML_ERROR_NONE || single_h -> state == JOIN_REQUESTED ) {
548+ /* If error occurred or join requested during invocation */
547549 if (alloc_output ) {
548550 single_h -> destroy_data_list =
549551 g_list_remove (single_h -> destroy_data_list , output );
550552 ml_tensors_data_destroy (output );
551553 }
552-
554+ /* If join requested, exit immediately without broadcast */
553555 if (single_h -> state == JOIN_REQUESTED )
554- goto exit ;
555- goto wait_for_next ;
556+ goto exit_thread ;
557+ } else {
558+ /* Process output data on success */
559+ if (alloc_output )
560+ __process_output (single_h , output );
556561 }
557562
558- if (alloc_output )
559- __process_output (single_h , output );
560-
561- /** loop over to wait for the next element */
562- wait_for_next :
563- single_h -> status = status ;
563+ /*Reset state and notify */
564564 if (single_h -> state == RUNNING )
565565 single_h -> state = IDLE ;
566+
566567 g_cond_broadcast (& single_h -> cond );
567568 }
568569
569- exit :
570- /* Do not set IDLE if JOIN_REQUESTED */
570+ exit_thread :
571+ /* Cleanup resources on exit */
571572 if (single_h -> state == JOIN_REQUESTED ) {
572- /* Release input and output data */
573573 if (single_h -> input )
574574 ml_tensors_data_destroy (single_h -> input );
575575
@@ -578,11 +578,11 @@ invoke_thread (void *arg)
578578 g_list_remove (single_h -> destroy_data_list , single_h -> output );
579579 ml_tensors_data_destroy (single_h -> output );
580580 }
581-
582581 single_h -> input = single_h -> output = NULL ;
583582 g_cond_broadcast (& single_h -> cond );
584- } else if (single_h -> state == RUNNING )
583+ } else if (single_h -> state == RUNNING ) {
585584 single_h -> state = IDLE ;
585+ }
586586 g_mutex_unlock (& single_h -> mutex );
587587 return NULL ;
588588}
0 commit comments