@@ -58,6 +58,41 @@ struct Source<D: Decoder> {
58
58
}
59
59
60
60
impl < D : Decoder > Source < D > {
61
+ cfg_if:: cfg_if! {
62
+ if #[ cfg( all( unix, feature = "signal-hook" ) ) ] {
63
+ fn new( limit: usize , input: D ) -> Self {
64
+ let exit_requested = {
65
+ use std:: sync:: atomic:: * ;
66
+ let e = Arc :: new( AtomicBool :: from( false ) ) ;
67
+
68
+ fn setup_signal( sig: i32 , e: Arc <AtomicBool >) {
69
+ unsafe {
70
+ signal_hook:: register( sig, move || {
71
+ if e. load( Ordering :: SeqCst ) {
72
+ std:: process:: exit( 128 + sig) ;
73
+ }
74
+ e. store( true , Ordering :: SeqCst ) ;
75
+ info!( "Exit requested, flushing." ) ;
76
+ } )
77
+ . expect( "Cannot register the signal hooks" ) ;
78
+ }
79
+ }
80
+
81
+ setup_signal( signal_hook:: SIGTERM , e. clone( ) ) ;
82
+ setup_signal( signal_hook:: SIGQUIT , e. clone( ) ) ;
83
+ setup_signal( signal_hook:: SIGINT , e. clone( ) ) ;
84
+
85
+ e
86
+ } ;
87
+ Self { limit, input, count: 0 , exit_requested, }
88
+ }
89
+ } else {
90
+ fn new( limit: usize , input: D ) -> Self {
91
+ Self { limit, input, count: 0 , }
92
+ }
93
+ }
94
+ }
95
+
61
96
fn read_frame < T : Pixel > (
62
97
& mut self , ctx : & mut Context < T > , video_info : VideoDetails ,
63
98
) -> Result < ( ) , CliError > {
@@ -446,36 +481,7 @@ fn run() -> Result<(), error::CliError> {
446
481
} ;
447
482
}
448
483
449
- #[ cfg( all( unix, feature = "signal-hook" ) ) ]
450
- let exit_requested = {
451
- use std:: sync:: atomic:: * ;
452
- let e = Arc :: new ( AtomicBool :: from ( false ) ) ;
453
-
454
- fn setup_signal ( sig : i32 , e : Arc < AtomicBool > ) {
455
- unsafe {
456
- signal_hook:: register ( sig, move || {
457
- if e. load ( Ordering :: SeqCst ) {
458
- std:: process:: exit ( 128 + sig) ;
459
- }
460
- e. store ( true , Ordering :: SeqCst ) ;
461
- info ! ( "Exit requested, flushing." ) ;
462
- } )
463
- . expect ( "Cannot register the signal hooks" ) ;
464
- }
465
- }
466
-
467
- setup_signal ( signal_hook:: SIGTERM , e. clone ( ) ) ;
468
- setup_signal ( signal_hook:: SIGQUIT , e. clone ( ) ) ;
469
- setup_signal ( signal_hook:: SIGINT , e. clone ( ) ) ;
470
-
471
- e
472
- } ;
473
-
474
- #[ cfg( all( unix, feature = "signal-hook" ) ) ]
475
- let mut source =
476
- Source { limit : cli. limit , input : y4m_dec, count : 0 , exit_requested } ;
477
- #[ cfg( not( all( unix, feature = "signal-hook" ) ) ) ]
478
- let mut source = Source { limit : cli. limit , input : y4m_dec, count : 0 } ;
484
+ let mut source = Source :: new ( cli. limit , y4m_dec) ;
479
485
480
486
if video_info. bit_depth == 8 {
481
487
do_encode :: < u8 , y4m:: Decoder < ' _ , Box < dyn Read > > > (
0 commit comments