[pulseaudio-discuss] [PATCH 4/4] Wrap clock_gettime and friends
rem at videolan.org
Wed Nov 4 06:26:15 PST 2009
On Wed, 4 Nov 2009 01:37:41 +0100, Daniel Mack <daniel at caiaq.de> wrote:
>> If HAVE_CLOCK_GETTIME is set, than this means that clock_gettime() is
>> available, too. So why are we emulating it then?
> Because CLOCK_REALTIME is undefined. I think the true reason is that
> HAVE_CLOCK_GETTIME is bogus in this case. It is reported to be supported
> but in fact it isn't.
> Maybe the real fix would be to check why. But that involves dealing with
> autofoo and their braindead m4 macro voodoo which always ruins my day ;)
clock_gettime() is indeed not supported by the antique MacOS libc. Then
again, as already pointed out by someone else in this thread,
gettimeofday() is just as good as clock_gettime(CLOCK_REALTIME) and more
portable. That assumes nobody cares about sub-microseconds precision. In
other words, clock_gettime() is really only useful if you want to use
another clock than the real-time one.
Then if you don't want to deal with autoconf, you can use POSIX defines. In
principle, _POSIX_MONOTONIC_CLOCK is non-negative if CLOCK_MONOTONIC is
supported (which implies clock_gettime()), and (-1) if it is not. In
practice, it is typically _not_ defined in the later case:
# define _POSIX_MONOTONIC_CLOCK (-1)
#if (_POSIX_MONOTONIC_CLOCK >= 0)
if (clock_gettime(CLOCK_MONOTONIC, ...)
clock_gettime(CLOCK_REALTIME, ...); /* run-time fall-back */
This will however seemingly break with the criminally buggy piece of crap
that is uClibc, which defines _POSIX_MONOTONIC_CLOCK to zero but lacks
clocks support altogether. Oh well...
More information about the pulseaudio-discuss