11use std:: {
22 error,
3- sync:: { atomic:: { AtomicBool , AtomicUsize , Ordering } , Arc } ,
3+ sync:: {
4+ atomic:: { AtomicBool , AtomicUsize , Ordering } ,
5+ Arc ,
6+ } ,
47 thread:: sleep,
58 time:: Duration ,
69} ;
@@ -15,7 +18,13 @@ use crate::core::{
1518} ;
1619
1720use super :: {
18- fasta_reader:: FastaReader , fusion_mapper:: FusionMapper , fusion_scan:: Error , html_reporter:: HtmlReporter , json_reporter:: JsonReporter , read:: { SequenceRead , SequenceReadCow } , read_match:: ReadMatch
21+ fasta_reader:: FastaReader ,
22+ fusion_mapper:: FusionMapper ,
23+ fusion_scan:: Error ,
24+ html_reporter:: HtmlReporter ,
25+ json_reporter:: JsonReporter ,
26+ read:: { SequenceRead , SequenceReadCow } ,
27+ read_match:: ReadMatch ,
1928} ;
2029
2130#[ derive( Debug ) ]
@@ -45,7 +54,7 @@ pub(crate) struct SingleEndScanner<'s> {
4554 m_produce_finished : AtomicBool ,
4655 m_thread_num : i32 ,
4756 m_fusion_mapper_o : Option < FusionMapper < ' s > > ,
48- m_thread_pool : ThreadPool ,
57+ m_thread_pool : Option < ThreadPool > ,
4958 input_seqs : Option < & ' s [ SequenceRead ] > ,
5059}
5160
@@ -57,9 +66,18 @@ impl<'s> SingleEndScanner<'s> {
5766 html : String ,
5867 json : String ,
5968 thread_num : i32 ,
60- input_seq_pairs : Option < & ' s [ SequenceRead ] > ,
69+ input_seq_pairs : Option < & ' s [ SequenceRead ] > ,
6170 ) -> Self {
62- let itp = ThreadPoolBuilder :: new ( ) . num_threads ( thread_num as usize ) . build ( ) . unwrap ( ) ;
71+ let itp = if thread_num > 1 {
72+ let tp = ThreadPoolBuilder :: new ( )
73+ . num_threads ( thread_num as usize )
74+ . build ( )
75+ . unwrap ( ) ;
76+
77+ Some ( tp)
78+ } else {
79+ None
80+ } ;
6381
6482 Self {
6583 m_fusion_file : fusion_file,
@@ -73,7 +91,6 @@ impl<'s> SingleEndScanner<'s> {
7391 m_fusion_mapper_o : None ,
7492 m_thread_pool : itp,
7593 input_seqs : input_seq_pairs,
76-
7794 // repo_not_full: Condvar::new(),
7895 // repo_not_empty: Condvar::new(),
7996 }
@@ -84,15 +101,30 @@ impl<'s> SingleEndScanner<'s> {
84101 }
85102
86103 fn _scan ( & mut self ) -> Result < bool , Error > {
87- self . m_thread_pool . scope ( |tps| {
88- tps. spawn ( |tps| self . producer_task ( ) . unwrap ( ) ) ;
104+ match self . m_thread_pool {
105+ Some ( ref itp) => {
106+ itp. scope ( |tps| {
107+ tps. spawn ( |tps| self . producer_task ( ) . unwrap ( ) ) ;
108+
109+ for t in ( 0 ..( rayon:: current_num_threads ( ) - 1 ) ) {
110+ tps. spawn ( |tps| {
111+ self . consumer_task ( ) . unwrap ( ) ;
112+ } )
113+ }
114+ } ) ;
89115
90- for t in ( 0 ..( rayon:: current_num_threads ( ) - 1 ) ) {
91- tps. spawn ( |tps| {
92- self . consumer_task ( ) . unwrap ( ) ;
93- } )
94- }
95- } ) ;
116+ } ,
117+ None => self . producer_task ( ) . unwrap ( ) ,
118+ }
119+ // self.m_thread_pool.scope(|tps| {
120+ // tps.spawn(|tps| self.producer_task().unwrap());
121+
122+ // for t in (0..(rayon::current_num_threads() - 1)) {
123+ // tps.spawn(|tps| {
124+ // self.consumer_task().unwrap();
125+ // })
126+ // }
127+ // });
96128
97129 log:: debug!( "Produced and consumed all the tasks." ) ;
98130 let m_fusion_mapper = self . m_fusion_mapper_o . as_mut ( ) . unwrap ( ) ;
@@ -116,7 +148,7 @@ impl<'s> SingleEndScanner<'s> {
116148 // exit(0);
117149
118150 log:: debug!( "run matches methods..." ) ;
119- m_fusion_mapper. filter_matches ( & self . m_thread_pool ) ;
151+ m_fusion_mapper. filter_matches ( self . m_thread_pool . as_ref ( ) ) ;
120152 m_fusion_mapper. sort_matches ( ) ;
121153 m_fusion_mapper. cluster_matches ( ) ;
122154
@@ -410,7 +442,6 @@ impl<'s> SingleEndScanner<'s> {
410442 // }
411443}
412444
413-
414445struct FastqReaderWrapper < ' s > {
415446 input_seq_pairs_iter : Option < std:: slice:: Iter < ' s , SequenceRead > > ,
416447 fastq_reader_pair : Option < FastqReader > ,
@@ -439,4 +470,4 @@ impl<'s> FastqReaderWrapper<'s> {
439470 . map ( SequenceReadCow :: Owned ) ,
440471 }
441472 }
442- }
473+ }
0 commit comments