Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: Processes
Chapter 3 - Time Manager


Using the Time Manager

The Time Manager is automatically initialized when the system starts up. At that time, the queue of Time Manager task records is empty. The Operating System, applications, and other software components may place records into the queue. Because the delay time for a given task can be as small as 20 microseconds, you need to install an element into the Time Manager queue before actually issuing a request to execute it at some future time. You place elements into the queue by calling the InsTime procedure or (if you need the fixed-frequency services of the extended Time Manager) the InsXTime procedure. To activate the request, call PrimeTime. The Time Manager then marks the specified task record as active by setting the high-order bit in the qType field of that record.

The tmAddr field of the Time Manager task record contains the address of a task. The Time Manager calls this task when the time delay specified by a previous call to PrimeTime has elapsed. The task can perform any desired actions, as long as it does not call the Memory Manager (either directly or indirectly) and does not depend on the validity of handles to unlocked blocks.

Note
If the routine specified in the Time Manager task record is located in your application's heap, then your application must still be active when the specified delay elapses, or the application should call RmvTime before it terminates. Otherwise, the Time Manager does not know that the address of that routine is not valid when the routine is called. The Time Manager then attempts to call the task, but with a stale pointer. If you want to let the application terminate after it has installed and activated a Time Manager task record, load the routine into the system heap. ·
There are two ways for an active queue element to become inactive. First, the specified time delay can elapse, in which case the routine pointed to by the tmAddr field is called. Second, your application can call the RmvTime procedure, in which case the amount of time remaining before the delay would have elapsed (the unused time) is reported in the tmCount field of the task record. This feature allows you to use the Time Manager to compute elapsed times (see the section "Computing Elapsed Time" on page 3-14), which is useful for obtaining performance measurements. Calling RmvTime removes an element from the queue whether or not that task is active when RmvTime is called.

To use the Time Manager for periodic execution of a task, simply have the routine pointed to by tmAddr call PrimeTime again. This technique is illustrated in the section "Performing Periodic Tasks" on page 3-13. Similarly, you can execute a Time Manager task a specific number of times by keeping a count of the number of times the task has been called. In cases where the task needs access to your application's global variables (such as a count variable), make sure that the A5 register points to your application's global variables when the task is executed and that A5 is restored to its original value when your task exits. A technique for this purpose is illustrated in "Using Application Global Variables in Tasks" on page 3-11.


Subtopics
Installing and Activating Tasks
Using Application Global Variables in Tasks
Performing Periodic Tasks
Computing Elapsed Time


Previous Book Contents Book Index Next

© Apple Computer, Inc.
17 JUN 1996