[Swan-dev] new delta time type

D. Hugh Redelmeier hugh at mimosa.com
Fri Jan 23 01:59:17 EET 2015


The new libevent code deals with times in milliseconds.

I assume that milliseconds isn't fundamental.  I imagine that the
actual use is for creating a struct timeval which actually uses
microseconds.  (Using "ms" in various names feels a little too
specific.)

It would be good if there were a new type to represent these values.
Currently unsigned long is used (mostly).  The C type system can be
used to catch errors if we help it by using a type that cannot
accidentally be interpreted as something else.  That's why I changed
all the other time types into structs (deltatime_t, realtime_t,
monotime_t).

An obvious choice would be struct timeval which already exists.
Doing arithmetic with a struct timeval is a bit awkward but not that
much arithmetic is being done and it can be encapsulated in functions.

If we invent our own type for this, what should it be called?  Due to
lack of imagination, I suggest fine_deltatime_t because it is a delta
time but with more precision.  But finetime_t is funnier and easier to
type.  hp_deltatime_t (for High Precision) would be OK.  Better ideas
are welcome.

Whatever name we chose, it should be used in renaming
event_schedule_ms.  If we chose struct timeval, we can just use the
existing event_schedule_tv.


More information about the Swan-dev mailing list