sergio masci wrote: > On Thu, 30 Jul 2009, Dave Tweed wrote: > > There is one ambiguity -- when the indices are equal, is the FIFO > > completely full or completely empty? This means that you can't > > actually completely fill the FIFO in a simple implementation. > > This means that the fifo buffer can only ever store a max of > ('buffer_length' - 1) items (in other words one item becomes a guard > item). Isn't that exactly what I said??? My point was, that if you add a simple boolean flag to the FIFO structure, you CAN completely fill it, and this actually has negligible impact on the overall code size, and does NOT affect its thread-safe properties. > NOTE: the way a temporary index is used to protect the location of fifo > item while it is being manipulated and consequently these routines are > *** INTERRUPT SAFE *** Actually, your temporary variable has nothing to do with making the routines thread/interrupt-safe. I don't know the complete specs of the language you're using, but using the variable appears to be just a performance optimization (to avoid having to recalculate the updated value at the end of fifo_write()) and/or a workaround for the limited expression-handling capabilities of the compiler. You could just as well have called fifo_full() from fifo_write(), and fifo_empty() from fifo_read(). -- Dave Tweed -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist