shared code for fifo