@@ -220,9 +220,7 @@ static void report_intermediate(void)
220220 silence intermediate reports at the end of the test
221221 */
222222 if (ck_pr_load_uint (& sb_globals .report_interval ) == 0 )
223- {
224223 return ;
225- }
226224
227225 sb_counters_agg_intermediate (cnt );
228226 report_get_common_stat (& stat , cnt );
@@ -914,9 +912,9 @@ static void *report_thread_proc(void *arg)
914912 sb_rand_thread_init ();
915913
916914 if (sb_lua_loaded () && sb_lua_report_thread_init ())
917- {
918915 return NULL ;
919- }
916+
917+ pthread_cleanup_push (sb_lua_report_thread_done , NULL );
920918
921919 log_text (LOG_DEBUG , "Reporting thread started" );
922920
@@ -944,6 +942,8 @@ static void *report_thread_proc(void *arg)
944942 pause_ns = next_ns - curr_ns ;
945943 }
946944
945+ pthread_cleanup_pop (1 );
946+
947947 return NULL ;
948948}
949949
@@ -963,9 +963,9 @@ static void *checkpoints_thread_proc(void *arg)
963963 sb_rand_thread_init ();
964964
965965 if (sb_lua_loaded () && sb_lua_report_thread_init ())
966- {
967966 return NULL ;
968- }
967+
968+ pthread_cleanup_push (sb_lua_report_thread_done , NULL );
969969
970970 log_text (LOG_DEBUG , "Checkpoints report thread started" );
971971
@@ -990,8 +990,7 @@ static void *checkpoints_thread_proc(void *arg)
990990 report_cumulative ();
991991 }
992992
993- if (sb_lua_loaded ())
994- sb_lua_report_thread_done ();
993+ pthread_cleanup_pop (1 );
995994
996995 return NULL ;
997996}
@@ -1149,26 +1148,6 @@ static int run_test(sb_test_t *test)
11491148 if (test -> ops .cleanup != NULL && test -> ops .cleanup () != 0 )
11501149 return 1 ;
11511150
1152- /* print test-specific stats */
1153- if (!sb_globals .error )
1154- {
1155- if (sb_globals .histogram )
1156- {
1157- log_text (LOG_NOTICE , "Latency histogram (values are in milliseconds)" );
1158- sb_histogram_print (& sb_latency_histogram );
1159- log_text (LOG_NOTICE , " " );
1160- }
1161-
1162- report_cumulative ();
1163- }
1164-
1165- pthread_mutex_destroy (& sb_globals .exec_mutex );
1166-
1167- /* finalize test */
1168- if (test -> ops .done != NULL )
1169- (* (test -> ops .done ))();
1170-
1171- /* Delay killing the reporting threads to avoid mutex lock leaks */
11721151 if (report_thread_created )
11731152 {
11741153 if (sb_thread_cancel (report_thread ) || sb_thread_join (report_thread , NULL ))
@@ -1189,6 +1168,25 @@ static int run_test(sb_test_t *test)
11891168 log_errno (LOG_FATAL , "Terminating the checkpoint thread failed." );
11901169 }
11911170
1171+ /* print test-specific stats */
1172+ if (!sb_globals .error )
1173+ {
1174+ if (sb_globals .histogram )
1175+ {
1176+ log_text (LOG_NOTICE , "Latency histogram (values are in milliseconds)" );
1177+ sb_histogram_print (& sb_latency_histogram );
1178+ log_text (LOG_NOTICE , " " );
1179+ }
1180+
1181+ report_cumulative ();
1182+ }
1183+
1184+ pthread_mutex_destroy (& sb_globals .exec_mutex );
1185+
1186+ /* finalize test */
1187+ if (test -> ops .done != NULL )
1188+ (* (test -> ops .done ))();
1189+
11921190 return sb_globals .error != 0 ;
11931191}
11941192
0 commit comments