About the Time Manager
About the Time Manager
You can use the Time Manager to schedule execution of a routine after a
specified amount of time has elapsed. The Time Manager topics includes all
the information about the original Time Manager, as well as additional
information about the revised Time Manager included with system software
version 6.0.3 (and later) and about the extended
Time Manager included with system software version 7.0 and above.
Because different versions of the Time Manager are available under
different system software versions, your application may need to determine
which version is available in its current operating environment. To do so, you
can use the Gestalt function explained in the Compatibility Guidelines.
To use this information, you should already be familiar with
operating-system queues
the Vertical Retrace Manager
You need to know about operating-system queues because all
Time Manager routines involve inserting entries into a queue and then
activating or removing queued entries. You should be acquainted with the
Vertical Retrace Manager because it provides an alternative (and
sometimes preferable) method for scheduling routines for future or periodic
execution.
The primary service that the Time Manager provides to applications is a
method for scheduling routines to execute at a later time. By suitably defining
the task that later executes, you can use the Time Manager to accomplish a
wide range of time-related activities. For example, because one of the actions a
routine can perform is to reschedule itself for later execution, the
Time Manager provides your application with a means to perform periodic
or repeated actions. You can use the Time Manager to
schedule routines to execute after a specified delay
set up tasks that run periodically
compute the time a routine takes to execute
coordinate and synchronize actions in the Macintosh computer
The Time Manager provides a hardware-independent method of performing
these and other time-related tasks. You should use the
Time Manager instead of cycle- counting timing loops, which can vary in
duration because they are dependent upon clock speed and interrupt-handling
speed. Furthermore, on machines with 68020 or 68030 micro processors, it
is almost impossible to rely on cycle- counting loops because instructions may
be both cached and pipelined. In such cases, it is very difficult to tell what part
of the instruction cycle the machine is currently in.
To use the Time Manager, you must first issue a request by passing the
Time Manager the address of a task record, one of whose fields contains the
address of the routine that is to execute. Then you need to activate that request
by specifying the delay until the routine is to execute. The
Time Manager maintains requests that you issue in a queue, whose
structure is similar to that of standard Macintosh operating-system queues.
Any number of outstanding requests can be in the Time Manager queue, and
each application can add any number of entries to the queue. If several requests
happen to schedule routines for execution at exactly the same time, those
routines will execute as close to the scheduled time as possible, in the order in
which they entered the Time Manager queue
The routine you place in the queue can perform any desired action so long as it
does not call the Memory Manager, either directly or in directly. You cannot
call the Memory Manager because Time Manager tasks execute at
interrupt time.