Menu

#128 fifo_queue only works iff 65536 % queue_size == 0

open
btnut (45)
5
2007-06-08
2007-01-10
No

the increment in fifo_queue should better do a
if first >= queue_size { first = 0 }
instead of first = (first + 1) % queue_size as this is incorrect for first = 65535.

example: queue_size = 10. first = 65535
6. element is addressed

increment: first = 65536 = 0 = 1. element but should be 7. element

Discussion

  • Matthias Ringwald

    • assigned_to: nobody --> freckle
     
  • Matthias Ringwald

    Logged In: YES
    user_id=687107
    Originator: YES

    I guess this is not a real bug. first should not be bigger than queue size.
    anyway, using % requires a 16-bit division for no reason. the if first >= queue_size is a simple 16 bit compare and hence much cheaper. I'll fix it.