[D-runtime] Why is clock_gettime() commented out?

Sean Kelly sean at invisibleduck.org
Fri Nov 19 10:40:29 PST 2010


On Nov 18, 2010, at 9:38 PM, Jonathan M Davis wrote:

> On Thursday 18 November 2010 21:24:16 Sean Kelly wrote:
>> On Nov 18, 2010, at 6:57 PM, Jonathan M Davis wrote:
>>> Is there a particular reason why clock_gettime() and various related
>>> posix C time functions are all commented out in core.sys.posix.time and
>>> core.sys.posix.signals? They're necessary to get either a realtime clock
>>> or a monotonic clock on Posix systems. It is true that that necessetates
>>> linking with -lrt, but as far as I know, all Posix systems should have
>>> librt, and the flag could be added to dmd.conf.
>>> 
>>> The stopwatch code in std.datetime is going to be potentially inaccurate
>>> without clock_gettime(), and the normal time code won't be quite as
>>> precise. Ideally, clock_gettime() would be available. Why are all of
>>> those time functions commented out? Were they causing problems somehow?
>> 
>> I don't recall.  I wrote all of the linux header blocks while the others
>> were submitted.  My best guess is that they weren't defined back when I
>> created the headers.  I see no problem with uncommenting them so long as
>> the functions exist though.  I'll verify and then make the change for
>> linux and OSX.
> 
> They definitely should exist. The caveat is that you have to link with librt for 
> them to work (why they didn't just stick them in glibc proper, I have no idea - 
> especially when anything that cares about precision time at all should be using 
> them).

clockid_t and related functions don't exist on OSX, so if you want to use them in std.datetime you'll have to fail gracefully to something less accurate.


More information about the D-runtime mailing list