@@ -2418,8 +2418,6 @@ class THD :public Statement,
24182418 // track down slow pthread_create
24192419 ulonglong prior_thr_create_utime, thr_create_utime;
24202420 ulonglong utime_after_query;
2421- my_time_t system_time;
2422- ulong system_time_sec_part;
24232421
24242422 // Process indicator
24252423 struct {
@@ -3430,30 +3428,37 @@ class THD :public Statement,
34303428 { query_start_sec_part_used=1 ; return start_time_sec_part; }
34313429 MYSQL_TIME query_start_TIME ();
34323430
3433- private:
3434- bool system_time_ge (my_time_t secs, ulong usecs)
3435- {
3436- return (system_time == secs && system_time_sec_part >= usecs) ||
3437- system_time > secs;
3438- }
3431+ struct {
3432+ my_hrtime_t start;
3433+ my_time_t sec;
3434+ ulong sec_part;
3435+ } system_time;
3436+
3437+ ulong systime_sec_part () { return system_time.sec_part ; }
3438+ my_time_t systime () { return system_time.sec ; }
34393439
3440+ private:
34403441 void set_system_time ()
34413442 {
34423443 my_hrtime_t hrtime= my_hrtime ();
3443- my_time_t secs= hrtime_to_my_time (hrtime);
3444- ulong usecs= hrtime_sec_part (hrtime);
3445- if (system_time_ge (secs, usecs))
3444+ my_time_t sec= hrtime_to_my_time (hrtime);
3445+ ulong sec_part= hrtime_sec_part (hrtime);
3446+ if (sec > system_time.sec ||
3447+ (sec == system_time.sec && sec_part > system_time.sec_part ) ||
3448+ hrtime.val < system_time.start .val )
34463449 {
3447- if (++system_time_sec_part == HRTIME_RESOLUTION)
3448- {
3449- ++system_time;
3450- system_time_sec_part= 0 ;
3451- }
3450+ system_time.sec = sec;
3451+ system_time.sec_part = sec_part;
34523452 }
34533453 else
34543454 {
3455- system_time= secs;
3456- system_time_sec_part= usecs;
3455+ if (system_time.sec_part < TIME_MAX_SECOND_PART)
3456+ system_time.sec_part ++;
3457+ else
3458+ {
3459+ system_time.sec ++;
3460+ system_time.sec_part = 0 ;
3461+ }
34573462 }
34583463 }
34593464
@@ -3468,8 +3473,8 @@ class THD :public Statement,
34683473 }
34693474 else
34703475 {
3471- start_time= system_time;
3472- start_time_sec_part= system_time_sec_part ;
3476+ start_time= system_time. sec ;
3477+ start_time_sec_part= system_time. sec_part ;
34733478 }
34743479 PSI_CALL_set_thread_start_time (start_time);
34753480 }
0 commit comments