On Wed, 18 Feb 2004 18:52:40 +0100, "Chris Apers" <[EMAIL PROTECTED]> wrote:
>HI, > >Is there any sample code that show a simple implementation >of mutex on PalmOS ? mainly to use with callback functions >and external buffer filler, i'd like to use it with SndStream functions. Why would you want mutual exclusion in SndStream callback functions? When the SndStream callback gets called, you must supply a buffer NOW, regardless of what background stuff is going on. Mutual exclusion would force the callback to wait under some conditions, and it just cannot do that because it is an interrupt service routine. I have written SndStream stuff, and I do not use any mutual exclusion. I have a cyclic list of buffers, one input pointer, and one output pointer. The callback advances the output pointer, and the main program advances the input pointer until it is equal to the output pointer. The callback calls EvtWakeup to ensure that the main program will get an nilEvent soon. My nilEvent processing sometimes processes more than one buffer. Mutual exclusion is never needed. Now it is true that I have no explicit protection against underrun (the input pointer falls one complete cycle behind the output pointer). But the design of buffer size and number of buffers makes that unlikely. And if it does happen, nothing crashes. Just one cycle of buffers is skipped and everything then continues normally. Robert Scott, Ypsilanti, MI (reply through this forum, not by e-mailing me directly) -- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/