Changeset 202 in flair-src for trunk/lib/FlairCore/src/Thread.cpp


Ignore:
Timestamp:
Nov 2, 2017, 3:04:47 PM (4 years ago)
Author:
Sanahuja Guillaume
Message:

modifs usleep

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/FlairCore/src/Thread.cpp

    r139 r202  
    9191  if (status != 0) {
    9292                char errorMsg[256];
    93     Err("%s, error rt_task_sleep_until (%s), resume time: %lld, actual time: "
    94         "%lld\n", ObjectName().c_str(), strerror_r(-status, errorMsg, sizeof(errorMsg)), time, GetTime());
     93    Err("%error rt_task_sleep_until (%s), resume time: %lld, actual time: "
     94        "%lld\n",strerror_r(-status, errorMsg, sizeof(errorMsg)), time, GetTime());
    9595        }
    9696// Printf("rt_task_sleep_until, resume time: %lld, actual time:
     
    9999  Time current = GetTime();
    100100  if (current < time) {
    101     usleep((time - current) / 1000);
     101    //usleep((time - current) / 1000);
     102    struct timespec req;
     103    req.tv_nsec = time - current;
     104    req.tv_sec = req.tv_nsec / 1000000000;
     105    req.tv_nsec %= 1000000000;
     106    struct timespec rem;
     107    if(nanosleep(&req,&rem)!=0) Err("error in nanosleep\n");//todo, handle EINTR
     108  } else {
     109    Err("error resume time is passed by %lldns\n", ( current-time));
    102110  }
    103111#endif
     
    112120        }
    113121#else
    114   usleep(time * 1000);
     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
    115129#endif
    116130}
     
    124138        }
    125139#else
    126   usleep(time);
     140  //usleep(time);
     141  struct timespec req;
     142  req.tv_nsec = time * 1000;
     143  req.tv_sec = req.tv_nsec / 1000000000;
     144  req.tv_nsec %= 1000000000;
     145  struct timespec rem;
     146  if(nanosleep(&req,&rem)!=0) Err("error in nanosleep\n");//todo, handle EINTR
    127147#endif
    128148}
Note: See TracChangeset for help on using the changeset viewer.