@@ -574,7 +574,26 @@ pub fn gen(files []&ast.File, mut table ast.Table, pref_ &pref.Preferences) GenO
574
574
b.write_string2 ('\n // V preincludes:\n ' , g.preincludes.str ())
575
575
b.write_string2 ('\n // V cheaders:\n ' , g.cheaders.str ())
576
576
if g.pcs_declarations.len > 0 {
577
- g.pcs_declarations.writeln ('double prof_measured_time = 0.0;' ) // does not work for multithreaded
577
+ g.pcs_declarations.writeln ('// V profile thread local:' )
578
+ g.pcs_declarations.writeln ('#if defined(__cplusplus) && __cplusplus >= 201103L' )
579
+ g.pcs_declarations.writeln ('\t #define PROF_THREAD_LOCAL thread_local' )
580
+ g.pcs_declarations.writeln ('#elif defined(__GNUC__) && __GNUC__ < 5' )
581
+ g.pcs_declarations.writeln ('\t #define PROF_THREAD_LOCAL __thread' )
582
+ g.pcs_declarations.writeln ('#elif defined(_MSC_VER)' )
583
+ g.pcs_declarations.writeln ('\t #define PROF_THREAD_LOCAL __declspec(thread)' )
584
+ g.pcs_declarations.writeln ('#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_THREADS__)' )
585
+ g.pcs_declarations.writeln ('\t #define PROF_THREAD_LOCAL _Thread_local' )
586
+ g.pcs_declarations.writeln ('#endif' )
587
+ g.pcs_declarations.writeln ('#ifndef PROF_THREAD_LOCAL' )
588
+ g.pcs_declarations.writeln ('\t #if defined(__GNUC__)' )
589
+ g.pcs_declarations.writeln ('\t\t #define PROF_THREAD_LOCAL __thread' )
590
+ g.pcs_declarations.writeln ('\t #endif' )
591
+ g.pcs_declarations.writeln ('#endif' )
592
+ g.pcs_declarations.writeln ('#ifdef PROF_THREAD_LOCAL' )
593
+ g.pcs_declarations.writeln ('\t static PROF_THREAD_LOCAL double prof_measured_time = 0.0;' )
594
+ g.pcs_declarations.writeln ('#else' )
595
+ g.pcs_declarations.writeln ('\t double prof_measured_time = 0.0; // multithreaded: wrong values for func times without its children' )
596
+ g.pcs_declarations.writeln ('#endif' )
578
597
b.write_string2 ('\n // V profile counters:\n ' , g.pcs_declarations.str ())
579
598
}
580
599
b.write_string2 ('\n // V includes:\n ' , g.includes.str ())
0 commit comments