Hi Folks,
I need the code to a couter that is allowed to overflow and where < > continue to tell earlier values from later values, for some defined interval.
To clarify, one possible implementation would be:
Consider two such counters cur
and dut
(device under test), consider two functions:
bool isEarlier(cur, dut) // Is dut earlier than cur?
bool isLater(cur, dut)
cur
and dut
are 16 bit, cur
has just overflowed, its current value is, lets say 5
. Depending on the value of dut
, the functions would return
- 0 to 16384: isEarlier ->
(cur < dut)
, isLater ->(cur > dut)
- 16384 to 32768: isEarlier -> false, isLater -> true
- 32768 to 49152: invalid, log error
- 49152 to 65536: isEarlier -> true, isLater -> false
Update: I can write the code myself, no problem. I'm just lazy. I know for fact that there is something like that in PostgreSQL (transaction ids wrap), I just couldn't locate the function that actually does it. I am pretty sure there is something like that in the Linux kernel, probably a macro. But neighther google codesearch, nor grep over /usr/include/linux could turn it up. Any ideas where it is?
Update: Clarified role of cur and dut. The "invalid" is there as a safeguard. As the differences between cur and dut become bigger, the function eventually complains.