When using the Allegro Games Library Shared Object every Game using it causes immediately 100% CPU load (on an X5000).
I investigated the source code of the library and found within the file "AllegroSDK_1.1_Source/src/amiga/atimer.c" the following timer thread code:
static void timer_thread_func(struct AmiThread *aAmiThread) { usecs_t Interval; ULONG Signal, ThreadSignal, TimerSignal; struct timeval OldTime, NewTime; /* Determine the time at which the first timer request was made so we can determine the */ /* real interval of the timer when it is called back, thus avoiding drift */ gettimeofday(&OldTime, NULL); /* And request a timer callback after 1 MS, just to kickstart the timer processing. Allegro's */ /* tick counter will handle calculating how often to call the callback in the future */ amithread_request_timeout(aAmiThread, 1000); ThreadSignal = (1 << aAmiThread->at_ThreadSignalBit); TimerSignal = (1 << aAmiThread->at_TimerMsgPort->mp_SigBit); for ( ; ; ) { Signal = IExec->Wait(ThreadSignal | TimerSignal); if (Signal & ThreadSignal) { break; } if (Signal & TimerSignal) { /* Calculate actual time elapsed */ gettimeofday(&NewTime, NULL); Interval = ((NewTime.tv_sec - OldTime.tv_sec) * 1000000 + (NewTime.tv_usec - OldTime.tv_usec)); OldTime = NewTime; /* Handle a tick */ Interval = timer_thread_handle_tick(Interval); amithread_request_timeout(aAmiThread, Interval); } } amithread_remove_sender(&gGraphicsThread); }
Line 20 creates an infinite loop. Maybe older OS 4.1 Versions (not FE) handled this better.
How could this be improved?
Thanks
@IamSONIC
Although in line 20 the infinit loop starts, its enthousiasm is tempered in line 22 with an explicit wait for either ThreadSignal or TimerSignal to be received. As in line 24 it is checked which of the two signals is gotten and ThreadSignal would break out of the loop, TimerSignal is the repetitive one. But have you verified that it is this loop that takes up all the cpu-cycles?
OldFart
@OldFart
Thanks for your reply. No i have not verified that this loop takes all the cycles. I don't know how to identify a specific task on AmigaOS in terms of performance.
Ok Embarrassing (╥_╥) ..did my homework about Line 22.
Got some information about that from this Video at 01:10:55 and from the AutoDocs
Wait(signalSet)
will cause the current task to suspend waiting for one or more signals :D