Skip to content

Discussion on PolledTimeout #5964

Closed
@d-a-v

Description

@d-a-v

Following

  1. 9a2ed27#r33052405 and
  2. 9a2ed27#r33052437

Regarding 2:

(@TD-er)
I guess we have to try then what the compiler makes of it.
As far as I know (current - _start) will give a high value if _start > current.
So then the division should also be a high number.
If the compiler should make it a signed integer and then casting it to uint, then we have other issues.

I made some test with gcc and it seems OK.
However, I totally agree it is not clear enough.
To ensure we stay within (unsigned) timeType bounds (with implicit modulo over range), I would propose to change

unsigned long n = (current - _start) / _timeout

to

unsigned long n = ((timeType)(current - _start)) / _timeout

Also, regarding 1)

return (!_neverExpires) && ((internalUnit - _start) >= _timeout);

to

return (!_neverExpires) && (((timeType)(internalUnit - _start)) >= _timeout);

This is supposed to be already implicit but it becomes clear and explicit this way, what do you think ?

and finally to add somewhere (a proposal from @devyte)

static_assert(std::is_unsigned<timeType>::value == true);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions