think about a counter
I think, using a counter it will work.
First take acount about some piece of memory that no applications can modify. Use a counter who will take the direction of the last digit in the fifo, when you push a digit in the fifo, use the number of the counter, then increment the counter.
When you have to pop, take the digit in the counter position, and then decrement the counter.
I hope this will help you.
PS Be sure to inicialice the counter, or to use a counter like:
accumulation data + inicial direction of the fifo memory.