joaopizani/avr-alarm — pull request #1 by joaopizani (2012-06-21 17:51:29+00:00)
Title: Merge blocking-insertion into master, solving timing issues

I think that all the timing problems that happened while using avr-alarm in conjunction with avr-tone are now **gone**!! \o/

So, I propose to merge the fix into master. What I did was basically:

1. To avoid **buffer underflow** (the queue getting empty while *insert* calls are still trying to finish): I greatly reduced the amount of time spent in relative_queue_insert. Now, to append elements to the queue takes **O(1)** time, and since appends are the MOST COMMON case, a great speedup results...

2. To avoid **buffer overflow** (too many insertions causing the queue to get too big and corrupt memory): In alarm.h there is a macro that defines a reasonable value for a maximum queue size. In alarm.c, in alarm_insert, there's a **busy-wait**, so that insertion is only performed when the queue is smaller than the maximum value.

Let's merge this? I'll test everything in actual hardware (my arduino), and if it goes well, I'll merge tomorrow :)