Changeset 22:8830afc9296c in rrlib_thread


Ignore:
Timestamp:
28.04.2014 20:06:33 (5 years ago)
Author:
Max Reichardt <mreichardt@…>
Branch:
13.10
Children:
23:3b0ff5b282a7, 24:d24b6f307548
Phase:
public
Message:

Fixed subtle bug (related to clock inconsistencies) in tLoopThread::MainLoop() and tidied it up

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tLoopThread.cpp

    r17 r22  
    107107      rrlib::time::tTimestamp now = local_use_application_time ? rrlib::time::Now() : rrlib::time::tBaseClock::now(); 
    108108      rrlib::time::tDuration last_cycle_time_tmp = now - last_cycle_start; 
    109       last_cycle_time.Store(last_cycle_time_tmp); 
    110       rrlib::time::tDuration wait_for_x = cycle_time - last_cycle_time_tmp; 
    111       if (wait_for_x < rrlib::time::tDuration::zero() && warn_on_cycle_time_exceed && cDISPLAYWARNINGS) 
     109      if (last_cycle_time_tmp.count() < 0) 
    112110      { 
    113         //System.err.println("warning: Couldn't keep up cycle time (" + (-waitForX) + " ms too long)"); 
    114         RRLIB_LOG_PRINT(WARNING, "Couldn't keep up cycle time (", rrlib::time::ToString(-wait_for_x), " too long)"); 
    115       } 
    116       else if (wait_for_x > cycle_time) 
    117       { 
    118         RRLIB_LOG_PRINT(WARNING, "Clock inconsistency detected: Last cycle started \"after\" this cycle. This would mean we'd have to wait for ", rrlib::time::ToString(wait_for_x), " now."); 
     111        RRLIB_LOG_PRINT(WARNING, "Clock inconsistency detected: Last cycle started ", -last_cycle_time_tmp.count(), " \"after\" this cycle."); 
     112        last_cycle_start = now; 
    119113        if (last_wait > rrlib::time::tDuration::zero()) 
    120114        { 
     
    127121        } 
    128122      } 
    129       else if (wait_for_x > rrlib::time::tDuration::zero()) 
     123      else 
    130124      { 
    131         last_wait = wait_for_x; 
    132         Sleep(wait_for_x, local_use_application_time, last_cycle_start + cycle_time); 
    133       } 
    134       last_cycle_start += cycle_time; 
    135       if (wait_for_x < rrlib::time::tDuration::zero()) 
    136       { 
    137         last_cycle_start = local_use_application_time ? rrlib::time::Now() : rrlib::time::tBaseClock::now(); 
     125        last_cycle_time.Store(last_cycle_time_tmp); 
     126        rrlib::time::tDuration wait_for_x = cycle_time - last_cycle_time_tmp; 
     127        if (wait_for_x < rrlib::time::tDuration::zero()) 
     128        { 
     129          if (warn_on_cycle_time_exceed && cDISPLAYWARNINGS) 
     130          { 
     131            RRLIB_LOG_PRINT(WARNING, "Couldn't keep up cycle time (", rrlib::time::ToString(-wait_for_x), " too long)"); 
     132          } 
     133          last_cycle_start = now; 
     134        } 
     135        else 
     136        { 
     137          last_wait = wait_for_x; 
     138          if (wait_for_x > rrlib::time::tDuration::zero()) 
     139          { 
     140            Sleep(wait_for_x, local_use_application_time, last_cycle_start + cycle_time); 
     141          } 
     142          last_cycle_start += cycle_time; 
     143        } 
    138144      } 
    139145    } 
Note: See TracChangeset for help on using the changeset viewer.