Hello Again. I've double (and triple checked) my logic and I'll keep it as it is for my project. Unless someone points a different mistake, that is... (atomicity, memory barriers...)
The trick I'm using to differentiate an empty buffer from a full one is explained here <http://en.wikipedia.org/wiki/Circular_buffer#Mirroring> and the specific case (simpler) when buffer size is a power of two is further down in that page. Short version is: you keep an extra bit for both the start and end pointers that represents the parity of how many times the pointer has circled the buffer. If both pointers point to the same slot and have circled the same number of times, the buffer is empty. If they point to the same slot but the end buffer has circled one more time (parity is different) then the buffer is full. Here are the checks: unsigned int is_full = (*buffer_end == (*buffer_start^buffer_size)); int buffer_is_empty(){ return (*buffer_start == *buffer_end); } Note that when incrementing the pointers, they don't go back to zero when they reach buffer_size, but when they reach 2*size-1: *buffer_start = (*buffer_start+1) & (2*buffer_size - 1); *buffer_end = (*buffer_end+1) & (2*buffer_size - 1); Thanks everyone for their input!! It rocks to have a solid and helpful community around the tools you use :) -- For more options, visit http://beagleboard.org/discuss --- You received this message because you are subscribed to the Google Groups "BeagleBoard" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
