@@ -10,19 +10,19 @@ use std::cmp::Ordering;
1010use std:: fs:: File ;
1111use std:: io:: { Read , Write , stderr} ;
1212use std:: path:: PathBuf ;
13- #[ cfg( not( all ( target_os = "wasi" , not ( target_feature = "atomics" ) ) ) ) ]
13+ #[ cfg( not( wasi_no_threads ) ) ]
1414use std:: sync:: mpsc:: { Receiver , SyncSender } ;
15- #[ cfg( not( all ( target_os = "wasi" , not ( target_feature = "atomics" ) ) ) ) ]
15+ #[ cfg( not( wasi_no_threads ) ) ]
1616use std:: thread;
1717
1818use itertools:: Itertools ;
1919use uucore:: error:: UResult ;
20- #[ cfg( not( all ( target_os = "wasi" , not ( target_feature = "atomics" ) ) ) ) ]
20+ #[ cfg( not( wasi_no_threads ) ) ]
2121use uucore:: error:: strip_errno;
2222
2323use crate :: Output ;
2424use crate :: chunks:: RecycledChunk ;
25- #[ cfg( not( all ( target_os = "wasi" , not ( target_feature = "atomics" ) ) ) ) ]
25+ #[ cfg( not( wasi_no_threads ) ) ]
2626use crate :: merge:: WriteableCompressedTmpFile ;
2727use crate :: merge:: WriteablePlainTmpFile ;
2828use crate :: merge:: WriteableTmpFile ;
@@ -41,7 +41,7 @@ const DEFAULT_BUF_SIZE: usize = 8 * 1024;
4141///
4242/// Uses the same chunked sort-write-merge strategy as the threaded version,
4343/// but reads and sorts each chunk sequentially on the calling thread.
44- #[ cfg( all ( target_os = "wasi" , not ( target_feature = "atomics" ) ) ) ]
44+ #[ cfg( wasi_no_threads ) ]
4545pub fn ext_sort (
4646 files : & mut impl Iterator < Item = UResult < Box < dyn Read + Send > > > ,
4747 settings : & GlobalSettings ,
@@ -159,17 +159,12 @@ pub fn ext_sort(
159159}
160160
161161/// Print a single sorted chunk.
162- #[ cfg( all( target_os = "wasi" , not( target_feature = "atomics" ) ) ) ]
163- fn print_chunk (
164- chunk : & Chunk ,
165- settings : & GlobalSettings ,
166- output : Output ,
167- ) -> UResult < ( ) > {
162+ #[ cfg( wasi_no_threads) ]
163+ fn print_chunk ( chunk : & Chunk , settings : & GlobalSettings , output : Output ) -> UResult < ( ) > {
168164 if settings. unique {
169165 print_sorted (
170166 chunk. lines ( ) . iter ( ) . dedup_by ( |a, b| {
171- compare_by ( a, b, settings, chunk. line_data ( ) , chunk. line_data ( ) )
172- == Ordering :: Equal
167+ compare_by ( a, b, settings, chunk. line_data ( ) , chunk. line_data ( ) ) == Ordering :: Equal
173168 } ) ,
174169 settings,
175170 output,
@@ -180,18 +175,12 @@ fn print_chunk(
180175}
181176
182177/// Merge two in-memory chunks and print.
183- #[ cfg( all( target_os = "wasi" , not( target_feature = "atomics" ) ) ) ]
184- fn print_two_chunks (
185- a : Chunk ,
186- b : Chunk ,
187- settings : & GlobalSettings ,
188- output : Output ,
189- ) -> UResult < ( ) > {
178+ #[ cfg( wasi_no_threads) ]
179+ fn print_two_chunks ( a : Chunk , b : Chunk , settings : & GlobalSettings , output : Output ) -> UResult < ( ) > {
190180 let merged_iter = a. lines ( ) . iter ( ) . map ( |line| ( line, & a) ) . merge_by (
191181 b. lines ( ) . iter ( ) . map ( |line| ( line, & b) ) ,
192182 |( line_a, a) , ( line_b, b) | {
193- compare_by ( line_a, line_b, settings, a. line_data ( ) , b. line_data ( ) )
194- != Ordering :: Greater
183+ compare_by ( line_a, line_b, settings, a. line_data ( ) , b. line_data ( ) ) != Ordering :: Greater
195184 } ,
196185 ) ;
197186 if settings. unique {
@@ -215,7 +204,7 @@ fn print_two_chunks(
215204/// Two threads cooperate: one reads input and writes temporary chunk files,
216205/// while the other sorts each chunk in memory. Once all chunks are written,
217206/// they are merged back together for final output.
218- #[ cfg( not( all ( target_os = "wasi" , not ( target_feature = "atomics" ) ) ) ) ]
207+ #[ cfg( not( wasi_no_threads ) ) ]
219208pub fn ext_sort (
220209 files : & mut impl Iterator < Item = UResult < Box < dyn Read + Send > > > ,
221210 settings : & GlobalSettings ,
@@ -276,7 +265,7 @@ pub fn ext_sort(
276265 }
277266}
278267
279- #[ cfg( not( all ( target_os = "wasi" , not ( target_feature = "atomics" ) ) ) ) ]
268+ #[ cfg( not( wasi_no_threads ) ) ]
280269fn reader_writer <
281270 F : Iterator < Item = UResult < Box < dyn Read + Send > > > ,
282271 Tmp : WriteableTmpFile + ' static ,
@@ -362,7 +351,7 @@ fn reader_writer<
362351}
363352
364353/// The function that is executed on the sorter thread.
365- #[ cfg( not( all ( target_os = "wasi" , not ( target_feature = "atomics" ) ) ) ) ]
354+ #[ cfg( not( wasi_no_threads ) ) ]
366355fn sorter ( receiver : & Receiver < Chunk > , sender : & SyncSender < Chunk > , settings : & GlobalSettings ) {
367356 while let Ok ( mut payload) = receiver. recv ( ) {
368357 payload. with_dependent_mut ( |_, contents| {
@@ -377,7 +366,7 @@ fn sorter(receiver: &Receiver<Chunk>, sender: &SyncSender<Chunk>, settings: &Glo
377366}
378367
379368/// Describes how we read the chunks from the input.
380- #[ cfg( not( all ( target_os = "wasi" , not ( target_feature = "atomics" ) ) ) ) ]
369+ #[ cfg( not( wasi_no_threads ) ) ]
381370enum ReadResult < I : WriteableTmpFile > {
382371 /// The input was empty. Nothing was read.
383372 EmptyInput ,
@@ -389,7 +378,7 @@ enum ReadResult<I: WriteableTmpFile> {
389378 WroteChunksToFile { tmp_files : Vec < I :: Closed > } ,
390379}
391380/// The function that is executed on the reader/writer thread.
392- #[ cfg( not( all ( target_os = "wasi" , not ( target_feature = "atomics" ) ) ) ) ]
381+ #[ cfg( not( wasi_no_threads ) ) ]
393382fn read_write_loop < I : WriteableTmpFile > (
394383 mut files : impl Iterator < Item = UResult < Box < dyn Read + Send > > > ,
395384 tmp_dir : & mut TmpDirWrapper ,
0 commit comments