@@ -559,6 +559,13 @@ static int obe_validate_input_params( obe_input_t *input_device )
559559 return 0 ;
560560}
561561
562+ static int __pthread_join ( pthread_t thread , void * * retval )
563+ {
564+ if ( thread )
565+ return pthread_join ( thread , retval );
566+ return -1 ;
567+ }
568+
562569int obe_probe_device ( obe_t * h , obe_input_t * input_device , obe_input_program_t * program )
563570{
564571 pthread_t thread ;
@@ -659,7 +666,7 @@ int obe_probe_device( obe_t *h, obe_input_t *input_device, obe_input_program_t *
659666 }
660667
661668 pthread_cancel ( thread );
662- pthread_join ( thread , & ret_ptr );
669+ __pthread_join ( thread , & ret_ptr );
663670
664671 cur_devices = h -> num_devices ;
665672
@@ -1224,7 +1231,7 @@ void obe_close( obe_t *h )
12241231 for ( int i = 0 ; i < h -> num_devices ; i ++ )
12251232 {
12261233 pthread_cancel ( h -> devices [i ]-> device_thread );
1227- pthread_join ( h -> devices [i ]-> device_thread , & ret_ptr );
1234+ __pthread_join ( h -> devices [i ]-> device_thread , & ret_ptr );
12281235 }
12291236
12301237 fprintf ( stderr , "input cancelled \n" );
@@ -1236,7 +1243,7 @@ void obe_close( obe_t *h )
12361243 h -> filters [i ]-> cancel_thread = 1 ;
12371244 pthread_cond_signal ( & h -> filters [i ]-> queue .in_cv );
12381245 pthread_mutex_unlock ( & h -> filters [i ]-> queue .mutex );
1239- pthread_join ( h -> filters [i ]-> filter_thread , & ret_ptr );
1246+ __pthread_join ( h -> filters [i ]-> filter_thread , & ret_ptr );
12401247 }
12411248
12421249 fprintf ( stderr , "filters cancelled \n" );
@@ -1248,7 +1255,7 @@ void obe_close( obe_t *h )
12481255 h -> encoders [i ]-> cancel_thread = 1 ;
12491256 pthread_cond_signal ( & h -> encoders [i ]-> queue .in_cv );
12501257 pthread_mutex_unlock ( & h -> encoders [i ]-> queue .mutex );
1251- pthread_join ( h -> encoders [i ]-> encoder_thread , & ret_ptr );
1258+ __pthread_join ( h -> encoders [i ]-> encoder_thread , & ret_ptr );
12521259 }
12531260
12541261 fprintf ( stderr , "encoders cancelled \n" );
@@ -1264,7 +1271,8 @@ void obe_close( obe_t *h )
12641271 pthread_mutex_lock ( & h -> obe_clock_mutex );
12651272 pthread_cond_broadcast ( & h -> obe_clock_cv );
12661273 pthread_mutex_unlock ( & h -> obe_clock_mutex );
1267- pthread_join ( h -> enc_smoothing_thread , & ret_ptr );
1274+ if ( h -> enc_smoothing_thread )
1275+ __pthread_join ( h -> enc_smoothing_thread , & ret_ptr );
12681276 }
12691277
12701278 fprintf ( stderr , "encoder smoothing cancelled \n" );
@@ -1274,7 +1282,7 @@ void obe_close( obe_t *h )
12741282 h -> cancel_mux_thread = 1 ;
12751283 pthread_cond_signal ( & h -> mux_queue .in_cv );
12761284 pthread_mutex_unlock ( & h -> mux_queue .mutex );
1277- pthread_join ( h -> mux_thread , & ret_ptr );
1285+ __pthread_join ( h -> mux_thread , & ret_ptr );
12781286
12791287 fprintf ( stderr , "mux cancelled \n" );
12801288
@@ -1283,7 +1291,7 @@ void obe_close( obe_t *h )
12831291 h -> cancel_mux_smoothing_thread = 1 ;
12841292 pthread_cond_signal ( & h -> mux_smoothing_queue .in_cv );
12851293 pthread_mutex_unlock ( & h -> mux_smoothing_queue .mutex );
1286- pthread_join ( h -> mux_smoothing_thread , & ret_ptr );
1294+ __pthread_join ( h -> mux_smoothing_thread , & ret_ptr );
12871295
12881296 fprintf ( stderr , "mux smoothing cancelled \n" );
12891297
@@ -1294,10 +1302,10 @@ void obe_close( obe_t *h )
12941302 h -> outputs [i ]-> cancel_thread = 1 ;
12951303 pthread_cond_signal ( & h -> outputs [i ]-> queue .in_cv );
12961304 pthread_mutex_unlock ( & h -> outputs [i ]-> queue .mutex );
1297- pthread_join ( h -> outputs [i ]-> output_thread , & ret_ptr );
1305+ __pthread_join ( h -> outputs [i ]-> output_thread , & ret_ptr );
12981306 /* could be blocking on OS so have to cancel thread too */
12991307 pthread_cancel ( h -> outputs [i ]-> output_thread );
1300- pthread_join ( h -> outputs [i ]-> output_thread , & ret_ptr );
1308+ __pthread_join ( h -> outputs [i ]-> output_thread , & ret_ptr );
13011309 }
13021310
13031311 fprintf ( stderr , "output thread cancelled \n" );
0 commit comments