The current implementation does not reliably initialize t0 once.
Additionally the initialization requires two calls to _gettimeofday().
Let's sacrifice a byte to keep the initialization status
and reduce the maximum number of calls to _gettimeofday().
This has caused issues in an application that invokes clock().
The problematic situation is as follows:
1) The program calls clock() which calls _times().
2) _gettimeofday(&t0, 0) puts 0 in t0.tv_usec (because less than 1 us has
elapsed since the beginning of time).
3) _gettimeofday(&t, 0) puts 1 in t.tv_usec (since now more than 1 us has
elapsed since the beginning of time).
4) That call to clock() returns 1 (the value from step 3 minus the value in
step 2).
5) The program does a second call to clock().
6) The code above still sees 0 in t0 so it tries to update t0 again and
_gettimeofday(&t0, 0) puts 1 in t0.tv_usec.
7) The _gettimeofday(&t, 0) puts 1 in t.tv_usec (since less than 1us has
elapsed since step 3).
8) clock() returns 0 (step 7 minus step 6) and indicates that time is
moving backwards.
Signed-off-by: Christoph Muellner <cmuellner@gcc.gnu.org>
bfin - Analog Devices Blackfin processor.
sparc - Fujitsu Sparclite board. Works on the ex930, ex931, ex933
hp74x - Hewlett Packard HP742 board. Also some support for the hp743.
m68hc11 - Motorola 68HC11 or 68HC12 support.
m68k - Motorola MVME135 and IDP board. For CPU32 systems.
mep - Toshiba Media Processor.
pa - WinBond and Oki boards with a PA.
mips - R3000 support. Array Tech LSI33k based RAID disk controller.
lm32 - Lattice Mico32 simulator.
epiphany - Adapteva Epiphany multicore processor.
or1k - OpenRISC 1000 processor.