@@ -536,6 +536,7 @@ ow_engine_init (struct ow_engine *engine, struct ow_device *device,
536536 int err ;
537537 ow_err_t ret = OW_OK ;
538538
539+ engine -> status = OW_ENGINE_STATUS_READY ;
539540 engine -> device = device ;
540541 engine -> usb .xfr_audio_in = NULL ;
541542 engine -> usb .xfr_audio_out = NULL ;
@@ -757,7 +758,14 @@ run_audio (void *data)
757758 engine -> context -> get_time ());
758759 }
759760
760- ow_engine_set_status (engine , OW_ENGINE_STATUS_BOOT );
761+ pthread_spin_lock (& engine -> lock );
762+ if (engine -> status <= OW_ENGINE_STATUS_STOP )
763+ {
764+ pthread_spin_unlock (& engine -> lock );
765+ return NULL ;
766+ }
767+ engine -> status = OW_ENGINE_STATUS_BOOT ;
768+ pthread_spin_unlock (& engine -> lock );
761769
762770 while (1 )
763771 {
@@ -769,12 +777,12 @@ run_audio (void *data)
769777
770778 //status == OW_ENGINE_STATUS_BOOT || status == OW_ENGINE_STATUS_CLEAR
771779
772- if (ow_engine_get_status (engine ) == OW_ENGINE_STATUS_CLEAR )
780+ pthread_spin_lock (& engine -> lock );
781+ if (engine -> status == OW_ENGINE_STATUS_CLEAR )
773782 {
774783 engine -> status = OW_ENGINE_STATUS_RUN ;
775784 }
776785
777- pthread_spin_lock (& engine -> lock );
778786 if (engine -> context -> dll )
779787 {
780788 if (engine -> status == OW_ENGINE_STATUS_BOOT )
@@ -890,7 +898,6 @@ ow_engine_start (struct ow_engine *engine, struct ow_context *context)
890898 {
891899 return OW_INIT_ERROR_NO_DLL ;
892900 }
893- engine -> status = OW_ENGINE_STATUS_READY ;
894901 }
895902
896903 debug_print (1 , "Starting thread..." );
@@ -906,7 +913,8 @@ ow_engine_start (struct ow_engine *engine, struct ow_context *context)
906913 }
907914
908915 //Wait till the thread has reached the USB loop
909- while (ow_engine_get_status (engine ) < OW_ENGINE_STATUS_WAIT )
916+ while (ow_engine_get_status (engine ) > OW_ENGINE_STATUS_STOP &&
917+ ow_engine_get_status (engine ) < OW_ENGINE_STATUS_WAIT )
910918 {
911919 usleep (PAUSE_TO_BE_WAITING_USECS );
912920 }
@@ -962,7 +970,10 @@ inline void
962970ow_engine_set_status (struct ow_engine * engine , ow_engine_status_t status )
963971{
964972 pthread_spin_lock (& engine -> lock );
965- engine -> status = status ;
973+ if (engine -> status >= OW_ENGINE_STATUS_READY )
974+ {
975+ engine -> status = status ;
976+ }
966977 pthread_spin_unlock (& engine -> lock );
967978}
968979
0 commit comments