medfall

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit e321958bfc3c3b7bab18f802c26aa524a1e174ff
parent 15c664e5dbedaa276d91a5dbeff4f5badb8a4965
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Sun Jan 17 23:12:43 +0000

Make stats_print slightly less thread unsafe

Diffstat:
stats.cc | 7+++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/stats.cc b/stats.cc @@ -47,13 +47,16 @@ void stats_record( Stats * stats, double x ) { } void stats_print( Stats * stats, const char * name ) { + // make a copy of the samples so other threads can't ruin our sort + double local_samples[ STATS_NUM_QUART_SAMPLES ]; u32 num_samples = min( stats->num_records, ( u64 ) STATS_NUM_QUART_SAMPLES ); - std::sort( stats->samples, stats->samples + num_samples ); + memcpy( local_samples, stats->samples, num_samples * sizeof( double ) ); + std::sort( local_samples, local_samples + num_samples ); printf( "[%s]\n\tn: %llu\n\tmean: %f\n\tstddev: %f\n\trange: %f to %f\n\t25%%: %f 75%%: %f", name, stats->num_records, stats_mean( stats ), stats_stddev( stats ), stats->min, stats->max, - stats->samples[ num_samples / 4 ], stats->samples[ num_samples * 3 / 4 ] + local_samples[ num_samples / 4 ], local_samples[ num_samples * 3 / 4 ] ); }