@@ -14,7 +14,7 @@ use std::{
1414use clap:: Parser ;
1515use cli:: Cli ;
1616use crossbeam:: {
17- channel:: { Receiver , Sender } ,
17+ channel:: { Receiver , Sender , never } ,
1818 select,
1919} ;
2020use image_match:: { cosine_similarity, image:: get_image_signature} ;
@@ -169,7 +169,6 @@ fn get_bucket_width(threshold: u8) -> f32 {
169169fn progress_bar_loop (
170170 calc_total_rx : Receiver < u64 > ,
171171 calc_count_rx : Receiver < u64 > ,
172- compare_count_rx : Receiver < u64 > ,
173172) {
174173 let bars = MultiProgress :: new ( ) ;
175174 let style = ProgressStyle :: with_template ( "{msg} [{bar:40.cyan/blue}] {pos:>7}/{len:7}" )
@@ -180,17 +179,19 @@ fn progress_bar_loop(
180179 calc_bar. set_style ( style. clone ( ) ) ;
181180 calc_bar. set_message ( "Calculating signatures" ) ;
182181
182+ let mut calc_total_rx = Some ( calc_total_rx) ;
183+
183184 loop {
184185 select ! {
185- recv( calc_total_rx) -> msg => if let Ok ( msg ) = msg {
186- let length = calc_bar . length ( ) . unwrap_or ( 0 ) + msg ;
187- calc_bar. set_length ( length) ;
188- } ,
189- recv ( calc_count_rx ) -> msg => if let Ok ( msg ) = msg {
190- calc_bar . inc ( msg ) ;
186+ recv( calc_total_rx. as_ref ( ) . unwrap_or ( & never ( ) ) ) -> msg => match msg {
187+ Ok ( msg ) => {
188+ let length = calc_bar. length( ) . unwrap_or ( 0 ) + msg ;
189+ calc_bar . set_length ( length ) ;
190+ } ,
191+ Err ( _ ) => calc_total_rx = None ,
191192 } ,
192- recv( compare_count_rx ) -> msg => match msg {
193- Ok ( _ ) => ( ) ,
193+ recv( calc_count_rx ) -> msg => match msg {
194+ Ok ( msg ) => calc_bar . inc ( msg ) ,
194195 Err ( _) => break ,
195196 } ,
196197 }
@@ -220,11 +221,10 @@ fn main_signatures(cli: Cli) {
220221
221222 let ( calc_total_tx, calc_total_rx) = crossbeam:: channel:: bounded ( 2 ) ;
222223 let ( calc_count_tx, calc_count_rx) = crossbeam:: channel:: bounded ( CHANNEL_BOUND ) ;
223- let ( compare_count_tx, compare_count_rx) = crossbeam:: channel:: bounded ( CHANNEL_BOUND ) ;
224224
225225 if !cli. pairs {
226226 thread:: spawn ( move || {
227- progress_bar_loop ( calc_total_rx, calc_count_rx, compare_count_rx ) ;
227+ progress_bar_loop ( calc_total_rx, calc_count_rx) ;
228228 } ) ;
229229 }
230230
@@ -415,23 +415,13 @@ fn main_signatures(cli: Cli) {
415415 pairings. push ( pair) ;
416416 }
417417
418- // println!("Reaching joins");
419- drop ( compare_count_tx) ;
420418 for thread in image_maker_threads {
421419 thread. join ( ) . unwrap ( ) ;
422420 }
423- // println!("Image maker threads joined");
424421
425422 for thread in compare_threads {
426423 thread. join ( ) . unwrap ( ) ;
427424 }
428- // eprintln!("Compare threads done");
429-
430- // let bundle = bundle
431- // .read()
432- // .expect("Unable to read image bundle after all threads have completed.");
433-
434- // let image_map: Vec<String> = bundle.image_map.iter().map(|s| s.path.clone()).collect();
435425
436426 let images = ret_rx. recv ( ) . unwrap ( ) ;
437427 drop ( ret_rx) ;
0 commit comments