@@ -94,22 +94,28 @@ pub(super) struct COVER_epoch_info_t {
9494 pub ( super ) size : u32 ,
9595}
9696
97- pub ( super ) struct COVER_best_t_inner { }
97+ pub ( super ) struct COVER_best_t_inner {
98+ pub ( super ) dict : Box < [ u8 ] > ,
99+ pub ( super ) dictSize : size_t ,
100+ pub ( super ) parameters : ZDICT_cover_params_t ,
101+ pub ( super ) compressedSize : size_t ,
102+ }
98103
99104impl COVER_best_t_inner {
100105 pub ( crate ) fn new ( ) -> Self {
101- Self { }
106+ Self {
107+ dict : Box :: default ( ) ,
108+ dictSize : 0 ,
109+ compressedSize : -( 1 as core:: ffi:: c_int ) as size_t ,
110+ parameters : ZDICT_cover_params_t :: default ( ) ,
111+ }
102112 }
103113}
104114
105115pub ( super ) struct COVER_best_t {
106116 pub ( super ) mutex : Mutex < COVER_best_t_inner > ,
107117 pub ( super ) cond : Condvar ,
108118 pub ( super ) liveJobs : size_t ,
109- pub ( super ) dict : Box < [ u8 ] > ,
110- pub ( super ) dictSize : size_t ,
111- pub ( super ) parameters : ZDICT_cover_params_t ,
112- pub ( super ) compressedSize : size_t ,
113119}
114120
115121impl COVER_best_t {
@@ -118,10 +124,6 @@ impl COVER_best_t {
118124 mutex : Mutex :: new ( COVER_best_t_inner :: new ( ) ) ,
119125 cond : Condvar :: new ( ) ,
120126 liveJobs : 0 ,
121- dict : Box :: default ( ) ,
122- dictSize : 0 ,
123- compressedSize : -( 1 as core:: ffi:: c_int ) as size_t ,
124- parameters : ZDICT_cover_params_t :: default ( ) ,
125127 }
126128 }
127129}
@@ -964,12 +966,15 @@ pub(super) fn COVER_checkTotalCompressedSize(
964966 totalCompressedSize
965967}
966968
967- pub ( super ) fn COVER_best_wait ( best : & mut COVER_best_t ) {
969+ pub ( super ) fn COVER_best_wait (
970+ best : & mut COVER_best_t ,
971+ ) -> std:: sync:: MutexGuard < ' _ , COVER_best_t_inner > {
968972 let mut guard = best. mutex . lock ( ) . unwrap ( ) ;
969973 #[ expect( clippy:: while_immutable_condition) ]
970974 while best. liveJobs != 0 {
971975 guard = best. cond . wait ( guard) . unwrap ( ) ;
972976 }
977+ guard
973978}
974979
975980pub ( super ) fn COVER_best_start ( best : & mut COVER_best_t ) {
@@ -985,19 +990,19 @@ pub(super) fn COVER_best_finish(
985990 let compressedSize = selection. totalCompressedSize ;
986991 let dictSize = selection. dictSize ;
987992 let mut liveJobs: size_t = 0 ;
988- let _guard = best. mutex . lock ( ) . unwrap ( ) ;
993+ let mut guard = best. mutex . lock ( ) . unwrap ( ) ;
989994 best. liveJobs = ( best. liveJobs ) . wrapping_sub ( 1 ) ;
990995 liveJobs = best. liveJobs ;
991- if compressedSize < best . compressedSize {
992- if let Some ( slice) = best . dict . get_mut ( ..selection. dictContent . len ( ) ) {
996+ if compressedSize < guard . compressedSize {
997+ if let Some ( slice) = guard . dict . get_mut ( ..selection. dictContent . len ( ) ) {
993998 slice. copy_from_slice ( & selection. dictContent ) ;
994999 } else {
995- best . dict = selection. dictContent . clone ( ) ;
1000+ guard . dict = selection. dictContent . clone ( ) ;
9961001 }
9971002
998- best . dictSize = dictSize;
999- best . parameters = parameters;
1000- best . compressedSize = compressedSize;
1003+ guard . dictSize = dictSize;
1004+ guard . parameters = parameters;
1005+ guard . compressedSize = compressedSize;
10011006 }
10021007 if liveJobs == 0 {
10031008 best. cond . notify_all ( ) ;
@@ -1316,7 +1321,7 @@ pub unsafe extern "C" fn ZDICT_optimizeTrainFromBuffer_cover(
13161321 if displayLevel >= 1 {
13171322 eprintln ! ( "Failed to initialize context" ) ;
13181323 }
1319- COVER_best_wait ( & mut best) ;
1324+ drop ( COVER_best_wait ( & mut best) ) ;
13201325 POOL_free ( pool) ;
13211326 return initVal;
13221327 }
@@ -1381,15 +1386,15 @@ pub unsafe extern "C" fn ZDICT_optimizeTrainFromBuffer_cover(
13811386 }
13821387 }
13831388
1384- COVER_best_wait ( & mut best) ;
1389+ drop ( COVER_best_wait ( & mut best) ) ;
13851390 COVER_ctx_destroy ( & mut ctx) ;
13861391 }
13871392
13881393 if displayLevel >= 2 {
13891394 println ! ( "\r {:79 }\r " , "" ) ;
13901395 }
13911396
1392- COVER_best_wait ( & mut best) ;
1397+ let best = COVER_best_wait ( & mut best) ;
13931398
13941399 let dictSize = best. dictSize ;
13951400 if ERR_isError ( best. compressedSize ) {
0 commit comments