pike.git / src / builtin_functions.c

version» Context lines:

pike.git/src/builtin_functions.c:4576: Inside #if undefined(HAVE_AND_USE_POLL)
  }   #ifndef HAVE_AND_USE_POLL   #undef HAVE_POLL   #endif      static void delaysleep(double delay, unsigned do_abort_on_signal,    unsigned do_microsleep)   {   #define POLL_SLEEP_LIMIT 0.02    - #ifdef HAVE_GETHRTIME -  hrtime_t t0,tv; - #else -  struct timeval t0,tv; - #endif +  struct timeval gtod_t0, gtod_tv; +  cpu_time_t t0, tv;       /* Special case, sleep(0) means 'yield' */    if(delay == 0.0)    {    check_threads_etc();    /* Since check_threads doesn't yield on every call, we need this    * to ensure th_yield gets called. */    pike_thread_yield();    return;    }       if(sizeof(FLOAT_TYPE)<sizeof(double))    delay += FLT_EPSILON*5; /* round up */    - #ifdef HAVE_GETHRTIME -  t0=tv=gethrtime(); - #define GET_TIME_ELAPSED tv=gethrtime() - #define TIME_ELAPSED (tv-t0)*1e-9 - #else -  GETTIMEOFDAY(&t0); -  tv=t0; - #define GET_TIME_ELAPSED GETTIMEOFDAY(&tv) - #define TIME_ELAPSED ((tv.tv_sec-t0.tv_sec) + (tv.tv_usec-t0.tv_usec)*1e-6) - #endif +  t0 = tv = get_real_time(); +  if (t0 == -1) { +  /* Paranoia in case get_real_time fails. */ +  /* fprintf (stderr, "get_real_time failed in sleep()\n"); */ +  GETTIMEOFDAY (&gtod_t0); +  gtod_tv = gtod_t0; +  }    - #define FIX_LEFT() \ -  GET_TIME_ELAPSED; \ -  left = delay - TIME_ELAPSED; \ + #define FIX_LEFT() \ +  if (t0 == -1) { \ +  GETTIMEOFDAY (&gtod_tv); \ +  left = delay - ((gtod_tv.tv_sec-gtod_t0.tv_sec) + \ +  (gtod_tv.tv_usec-gtod_t0.tv_usec)*1e-6); \ +  } \ +  else { \ +  tv = get_real_time(); \ +  left = delay - (tv - t0) * (1.0 / CPU_TIME_TICKS); \ +  } \    if (do_microsleep) left-=POLL_SLEEP_LIMIT;       if (!do_microsleep || delay>POLL_SLEEP_LIMIT)    {    for(;;)    {    double left;    /* THREADS_ALLOW may take longer time then POLL_SLEEP_LIMIT */    THREADS_ALLOW();    FIX_LEFT();
pike.git/src/builtin_functions.c:4634:    return;    }    FIX_LEFT();    if(left<=0.0)    break;    check_threads_etc();    }    GETTIMEOFDAY (&current_time);    }    -  if (do_microsleep) -  while (delay>TIME_ELAPSED) -  GET_TIME_ELAPSED; +  if (do_microsleep) { +  if (t0 == -1) { +  while (delay> ((gtod_tv.tv_sec-gtod_t0.tv_sec) + +  (gtod_tv.tv_usec-gtod_t0.tv_usec)*1e-6)) +  GETTIMEOFDAY (&gtod_tv);    } -  +  else { +  while (delay> (tv - t0) * (1.0 / CPU_TIME_TICKS)) +  tv = get_real_time(); +  } +  }    -  +  /* fprintf (stderr, "slept %g\n", (tv - t0) * (1.0 / CPU_TIME_TICKS)); */ + } +    /*! @decl void sleep(int|float s, void|int abort_on_signal)    *!    *! This function makes the program stop for @[s] seconds.    *!    *! Only signal handlers can interrupt the sleep, and only when    *! @[abort_on_signal] is set. If more than one thread is running    *! the signal must be sent to the sleeping thread. Other callbacks    *! are not called during sleep.    *!    *! If @[s] is zero then this thread will yield to other threads but