parrotcode: Timer | |
Contents | PMCs |
src/pmc/timer.pmc - Timer
new P0, 'Timer'
set P0[.PARROT_TIMER_SEC], I_seconds # whole seconds
set P0[.PARROT_TIMER_USEC], I_micro seconds # and/or micro seconds
set P0[.PARROT_TIMER_NSEC], N_seconds_frac # or fraction in seconds
set P0[.PARROT_TIMER_REPEAT], I_repeat # 0 = one shot ...
set P0[.PARROT_TIMER_HANDLER], P_sub # set handler sub PMC
invoke P0 # start timer
set P0[.PARROT_TIMER_RUNNING], 1 # same
new P0, 'Timer', P1 # set everything
set I0, P0[.PARROT_TIMER_SEC] # query current timer status
set N0, P0[.PARROT_TIMER_NSEC]
...
set P0[.PARROT_TIMER_RUNNING], 0 # turn timer off
This is the Timer base class
Running timers are kept in a linked list. Each timer has a tick count, which gets decremented if the system timer expires. If the tick count reaches zero, the timer handler gets invoked via Parrot's event handling code.
The Timer resolution is operating system dependent. It's only guaranteed that the Timer will fire some time after the programmed interval.
The Timer stops after invoking the handler (repeat + 1) times. To create a Timer that will run forever, set "repeat" to -1. Turning the Timer off preserves set values; the Timer is not destroyed.
When setting both PARROT_TIMER_SEC
and PARROT_TIMER_USEC
it must be done in that sequence, whole seconds first. If a timer is constructed with an initializer and it should be run immediately, the PARROT_TIMER_RUNNING
value has to be in the last key of the initializer.
static void add_timer(PARROT_INTERP, PMC *pmc)
static void del_timer(PARROT_INTERP, PMC *pmc)
void init()
void init_pmc(PMC *init)
void destroy()
INTVAL get_integer_keyed_int(INTVAL key)
key
.PMC *get_pmc_keyed_int(INTVAL key)
key
.FLOATVAL get_number_keyed_int(INTVAL key)
key
.void set_integer_keyed_int(INTVAL key, INTVAL value)
key
to value
.void set_pmc_keyed_int(INTVAL key, PMC *value)
key
to *value
.opcode_t *invoke(void *next)
void set_number_keyed_int(INTVAL key, FLOATVAL value)
key
to value
.Initial proposal by leo 2003.07.15
Initial revision 2003.07.17
Switch to events 2004.01.07
|