[PATCH weston 2/7] timespec: Add timespec_add_msec helper
Daniel Stone
daniel at fooishbar.org
Tue Feb 14 14:27:44 UTC 2017
Hi,
On 14 February 2017 at 14:24, Pekka Paalanen <ppaalanen at gmail.com> wrote:
> On Tue, 14 Feb 2017 13:18:02 +0000
> Daniel Stone <daniels at collabora.com> wrote:
>> +/* Add a millisecond value to a timespec
>> + *
>> + * \param r[out] result: a + b
>> + * \param a[in] base operand as timespec
>> + * \param b[in] operand in milliseconds
>> + */
>> +static inline void
>> +timespec_add_msec(struct timespec *r, const struct timespec *a, int64_t b)
>> +{
>> + r->tv_sec = a->tv_sec + (b / 1000);
>> + r->tv_nsec = a->tv_nsec + ((b % 1000) * 1000000);
>> +
>> + if (r->tv_nsec >= NSEC_PER_SEC) {
>> + r->tv_sec++;
>> + r->tv_nsec -= NSEC_PER_SEC;
>> + } else if (r->tv_nsec <= -NSEC_PER_SEC) {
>
> The same problem as with the previous patch, tv_nsec cannot be allowed
> negative.
Same rationale. In particular, this is used later in the series to
subtract repaint_window from the timespec.
>> + r->tv_sec--;
>> + r->tv_nsec += NSEC_PER_SEC;
>> + }
>> +}
>
> Any reason to not write this as a call to timespec_add_nsec()?
> The testing added below is very thin otherwise.
I think the rationale was to try to avoid overflow in super
pathological cases. But I'm not really attached to enormous
millisecond input values, so could just trivially reimplement it on
top of the _nsec variant.
Cheers,
Daniel
More information about the wayland-devel
mailing list