[comp.sys.mac] TimeMgr

peirce@the780.dec.com.UUCP (02/09/87)

Recently I was trying to use the new time manager calls from LightSpeed C.
The thing seemed to work nicely except that a variable stored after
the TMTask record kept getting clobbered.  Upon further examination, I
noticed that there was a field called tmCount in the TMTask record which
is declared as an Int.  Both the LightSpeed C include file and the time
manager chapter of Inside Mac (marked "Final Draft 6/6/86") declare it
that way.  Now, even though it's marked "reserved" it appears to contain
the millisecond countdown set in the PrimeTime() call.  Unfortunately, 
the counting is happening in a long word! (which makes sense since
PrimeTime takes a long word of milliseconds) and clobbers anything stored
just beyond the record.  I changed the declaration to a long and all
seems well.

I talked to tech support at Think, and the guy didn't have any insight into
the problem (in fact he seemed to think that the time manager didn't work -
it does with this change!).

Has anyone else tried the time manager? or is this really a bug in the
documentation (and include file)?

I'll include my little test program that redeclares the TMTask type following
this text...

-- michael

---------------------------------------------------------------------------
#include "stdio.h"
#include "TimeMgr.h"
#include "OSUtil.h"

typedef struct newTMTask {
	struct QElem		*qLink;
	int			qType;
	ProcPtr			tmAddr;
	long			tmCount; /*** was an int (16-bit) ***/
} newTMTask;

newTMTask	Beep1_task;
int		sync;

main()
{
pascal	Beep1();

	printf("Begin...\n");
	sync = 0;

	Beep1_task.tmAddr = (ProcPtr) Beep1;

		printf("tmCnt  = %ld\n",Beep1_task.tmCount);
	InsTime(&Beep1_task);
		printf("tmCnt  = %ld\n",Beep1_task.tmCount);
	Debugger();
	PrimeTime(&Beep1_task,500);
		printf("tmCnt  = %ld\n",Beep1_task.tmCount);
		printf("tmCnt  = %ld\n",Beep1_task.tmCount);
		printf("tmCnt  = %ld\n",Beep1_task.tmCount);
		printf("tmCnt  = %ld\n",Beep1_task.tmCount);
		printf("tmCnt  = %ld\n",Beep1_task.tmCount);
		printf("tmCnt  = %ld\n",Beep1_task.tmCount);
		printf("tmCnt  = %ld\n",Beep1_task.tmCount);
		printf("tmCnt  = %ld\n",Beep1_task.tmCount);
	while (sync==0) {}
	printf("Done\n");
}

pascal Beep1()
{
	SetUpA5();
	SysBeep(1);
	RmvTime(&Beep1_task);
	sync = 1;
	RestoreA5();
}

/***** Observed result...

Begin...
tmCnt  = 500
tmCnt  = 416
tmCnt  = 332
tmCnt  = 248
tmCnt  = 164
tmCnt  = 80
tmCnt  = 0
tmCnt  = 0
Done

*********/