corsis/clock — pull request #15 by mboes (2014-10-26 16:55:46+00:00)
Title: Move cross-platform clock abstraction from C to Haskell

There are several reasons for this move. One is performance. For
compliant POSIX systems, time.h already provides all that we need,
without the need for wrapper functions. The C code used to define
a common cross-platform API, that each platform implemented differently.
But the problem with this approach is that GHC can't inline C wrapper
functions. The common API was introducing an extra layer of function
calls, but these cannot be eliminated by GHC, when it otherwise could if
the cross-platform API abstraction was done in Haskell instead.

The other reason is better portability and safety. Darwin and POSIX both
use `struct timespec` to encode clock readings. But because Windows does
not, the lowest common denominator was a two element array of longs.
These arrays were cast to `struct timespec`, but on some systems `time_t` is
32-bits, which we can't just assume to be the size of a `long`. On such
systems casting would yield incorrect results. Not to mention that on
modern 32-bit systems `time_t` is `long long`, again yielding incorrect
results. Also, it's best not to rely on C's struct layout semantics to
match exactly that of a two-element array.