File tree Expand file tree Collapse file tree 3 files changed +16
-1
lines changed Expand file tree Collapse file tree 3 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -127,6 +127,7 @@ fn app_view() -> impl IntoView {
127
127
12.0 ,
128
128
None ,
129
129
& logger_for_thread,
130
+ None
130
131
) ;
131
132
doc_subset. lock ( ) . unwrap ( ) . to_document ( & mut doc) ;
132
133
let f = File :: create ( path_for_thread. join ( "output.pdf" ) ) . unwrap ( ) ;
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ use c2pdf::logging::Logger;
6
6
use core:: f32;
7
7
use printpdf:: * ;
8
8
use std:: fs:: File ;
9
+ use std:: num:: NonZeroU8 ;
9
10
use std:: path:: PathBuf ;
10
11
use std:: time:: Instant ;
11
12
// This makes `FromArgs` happy
@@ -65,6 +66,10 @@ struct Arguments {
65
66
/// text to add to (the top of) every page
66
67
#[ argh( option) ]
67
68
page_text : Option < String > ,
69
+
70
+ /// number of threads to use for processing
71
+ #[ argh( option) ]
72
+ threads : Option < NonZeroU8 > ,
68
73
}
69
74
fn main ( ) {
70
75
// Parse args
@@ -98,6 +103,7 @@ fn main() {
98
103
args. font_size ,
99
104
args. page_text ,
100
105
& logger,
106
+ args. threads ,
101
107
) ;
102
108
doc_subset. lock ( ) . unwrap ( ) . to_document ( & mut doc) ;
103
109
let num_pages = doc. pages . len ( ) ;
Original file line number Diff line number Diff line change 8
8
9
9
use std:: {
10
10
cmp:: Ordering ,
11
+ num:: NonZeroU8 ,
11
12
path:: PathBuf ,
12
13
sync:: { Arc , Mutex } ,
13
14
} ;
@@ -43,6 +44,7 @@ impl CodeToPdf {
43
44
font_size : f32 ,
44
45
page_text : Option < String > ,
45
46
logger : & Logger ,
47
+ threads : Option < NonZeroU8 > ,
46
48
) -> ( Arc < Mutex < DocumentSubset > > , usize ) {
47
49
let doc_subset = DocumentSubset :: default ( ) ;
48
50
let ss = two_face:: syntax:: extra_newlines ( ) ;
@@ -75,7 +77,13 @@ impl CodeToPdf {
75
77
let local_highlighter_config = ThreadLocal :: < Arc < Mutex < HighlighterConfig > > > :: new ( ) ;
76
78
77
79
let doc_subset = Arc :: new ( Mutex :: new ( doc_subset) ) ;
78
-
80
+ if let Some ( threads) = threads {
81
+ // Build the global threadpool with the correct number of threads
82
+ rayon:: ThreadPoolBuilder :: new ( )
83
+ . num_threads ( u8:: from ( threads) as usize )
84
+ . build_global ( )
85
+ . unwrap ( ) ;
86
+ }
79
87
walker. enumerate ( ) . par_bridge ( ) . for_each ( |( i, result) | {
80
88
// let mut doc = PdfDocument::new(&args.name);
81
89
let c2pdf_mutex = local_c2pdf. get_or ( || {
You can’t perform that action at this time.
0 commit comments