[comp.sys.mac.programmer] Asynchronous callback routine in MPW C 3.1?

lipa@NEON.STANFORD.EDU ("William J. Lipa") (03/08/91)

I am having a lot of trouble porting a Sound Manager package to MPW C 3.1.
The routines work correctly under Think C 4.0.2 and gcc 1.37, as far as I
know. Has anyone got a callback routine to work with this compiler? All I
need to do is put the channel pointer into a global array of pointers that
will get disposed of the next time through the event loop.

My callback routine follows, in the hope that I'm making some obvious
blunder.

pascal void soundCompletion(channel, command)
SndChannelPtr channel;
SndCommand *command;
{
	tblong myA5;
	int i;
	
	if (command->param1 == kSoundComplete)
	{
		myA5 = SetA5(command->param2);
		
   /* Go through the table until empty entry is found or run off the end. */
		for (i = 0; i < kMaxPendingDisposes; i++)
		{
			if (!pgDisposeMe[i])
			{
				pgDisposeMe[i] = channel;
				pgNeedDispose = true;
				break;
			}
		}
		if (i >= kMaxPendingDisposes)	/* no empty entry */
			pgInterruptError = true;
		myA5 = SetA5(myA5);
	}
}

The exact symptom is that very often the routine can't find an empty element
in the pgDisposeMe array (which is declared volatile), sometimes even
when only one sound has been played. It then sets the pgInterruptError
flag to true and subsequently I catch the error.

All advice appreciated! I need to use an array of channels waiting to be
disposed instead of a simple flag because I can have multiple sounds running
at once under the new 6.0.7 Sound Manager. But if anyone has gotten
any sort of sound completion routine to work under MPW C, I would very
much like to see it.

Bill
PS. I explicitly intialize each element of pgDisposeMe to 0 to be sure.