NAME

src/pmc/timer.pmc - Timer PMC

SYNOPSIS

    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

DESCRIPTION

This is the Timer base class

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.

Functions

void init()
Initializes the timer.
void init_pmc(PMC *init)
Takes an even-length collection of keys and values.
PMC *clone()
Create a copy of the timer, resetting status, id, and birthtime.
INTVAL get_integer_keyed_int(INTVAL key)
Returns the timer info for key.
PMC *get_pmc_keyed_int(INTVAL key)
Returns the PMC associated with key.
FLOATVAL get_number_keyed_int(INTVAL key)
Returns the number associated with key.
void set_integer_keyed_int(INTVAL key, INTVAL value)
Sets the value associated with key to value.
void set_pmc_keyed_int(INTVAL key, PMC *value)
Sets the PMC associated with key to *value.
opcode_t *invoke(void *next)
Either: Initially schedule the timer. or Invoke the codeblock and schedule any repeats.
void set_number_keyed_int(INTVAL key, FLOATVAL value)
Sets the floating-point value associated with key to value.
void mark()
Mark any referenced strings and PMCs.