Changeset 307 in flair-src for trunk/lib/FlairCore


Ignore:
Timestamp:
Mar 8, 2019, 10:30:25 AM (6 years ago)
Author:
Sanahuja Guillaume
Message:

resove bug in times

Location:
trunk/lib/FlairCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/FlairCore

    • Property svn:ignore set to
      build_x86_64
      build_core2_64
      build_armv7a_neon
      build_armv5te
      build_arm
      build
      .codelite
      .clang
  • trunk/lib/FlairCore/src/Thread.cpp

    r252 r307  
    9898#else
    9999  Time current = GetTime();
     100
    100101  if (current < time) {
    101102    //usleep((time - current) / 1000);
     103    Time tmp=time - current;
    102104    struct timespec req;
    103     req.tv_nsec = time - current;
    104     req.tv_sec = req.tv_nsec / 1000000000;
    105     req.tv_nsec %= 1000000000;
     105    req.tv_sec = tmp / (Time)1000000000;
     106    req.tv_nsec = tmp%(Time)1000000000;
    106107    struct timespec rem;
    107108    if(nanosleep(&req,&rem)!=0) Err("error in nanosleep\n");//todo, handle EINTR
     
    113114
    114115void Thread::SleepMS(uint32_t time) const {
    115 #ifdef __XENO__
    116   int status = rt_task_sleep(time * 1000 * 1000);
    117   if (status != 0) {
    118                 char errorMsg[256];
    119     Err("erreur rt_task_sleep (%s)\n", strerror_r(-status, errorMsg, sizeof(errorMsg)));
    120         }
    121 #else
    122   //usleep(time * 1000);
    123   struct timespec req;
    124   req.tv_nsec = time * 1000000;
    125   req.tv_sec = req.tv_nsec / 1000000000;
    126   req.tv_nsec %= 1000000000;
    127   struct timespec rem;
    128   if(nanosleep(&req,&rem)!=0) Err("error in nanosleep\n");//todo, handle EINTR
    129 #endif
     116    SleepUS(time*1000);
    130117}
    131118
     
    140127  //usleep(time);
    141128  struct timespec req;
    142   req.tv_nsec = time * 1000;
    143   req.tv_sec = req.tv_nsec / 1000000000;
    144   req.tv_nsec %= 1000000000;
     129  req.tv_sec = (Time)time / (Time)1000;
     130  req.tv_nsec = (Time)time%(Time)1000;
    145131  struct timespec rem;
    146132  if(nanosleep(&req,&rem)!=0) Err("error in nanosleep\n");//todo, handle EINTR
  • trunk/lib/FlairCore/src/Thread_impl.cpp

    r250 r307  
    174174
    175175#ifdef __XENO__
    176   int status = rt_task_set_periodic(&task_rt, TM_NOW, period * 1000);
     176  int status = rt_task_set_periodic(&task_rt, TM_NOW, (Time)period * (Time)1000);
    177177  if (status != 0) {
    178178                char errorMsg[256];
     
    181181#else
    182182  if (period_set) {
    183     next_time -= period;
    184     next_time += period * 1000;
    185   } else next_time=GetTime()+period*1000;
    186 #endif
    187   this->period = period * 1000;
     183    next_time -= (Time)period;
     184    next_time += (Time)period * (Time)1000;
     185  } else next_time=GetTime()+(Time)period*(Time)1000;
     186#endif
     187  this->period = (Time)period * (Time)1000;
    188188  period_set = true;
    189189}
     
    192192
    193193void Thread_impl::SetPeriodMS(uint32_t period) {
    194   if (period == 0) {
    195     self->Err("Period must be>0\n");
    196     return;
    197   }
    198 
    199 #ifdef __XENO__
    200   int status = rt_task_set_periodic(&task_rt, TM_NOW, period * 1000 * 1000);
    201   if (status != 0) {
    202                 char errorMsg[256];
    203     self->Err("Error rt_task_set_periodic %s\n", strerror_r(-status, errorMsg, sizeof(errorMsg)));
    204         }
    205 #else
    206   if (period_set) {
    207     next_time -= period;
    208     next_time += period * 1000 * 1000;
    209   } else next_time=GetTime()+period*1000*1000;
    210 #endif
    211   this->period = period * 1000 * 1000;
    212   period_set = true;
     194  SetPeriodUS(period*1000);
    213195}
    214196
Note: See TracChangeset for help on using the changeset viewer.