Branch: Tag:

2010-10-24

2010-10-24 18:13:14 by Martin Stjernholm <mast@lysator.liu.se>

Safeguard the old clock(3) code against wraparounds.

1495:    }    }   #elif defined (USE_CLOCK_FOR_SLICES) -  if (clock() - thread_start_clock < (clock_t) (CLOCKS_PER_SEC / 20)) +  { +  clock_t clock_now = clock(); +  if (clock_now - thread_start_clock < 0) +  /* clock counter has wrapped since the start of the time slice. +  * Let's reset and yield. */ +  thread_start_clock = 0; +  else if (clock_now - thread_start_clock < (clock_t) (CLOCKS_PER_SEC / 20))    return; -  +  }   #else    static int div_;    if(div_++ & 255)