Skip to content

Commit

Permalink
Cleanup Alarm PMC. Add some comments/docs. Cleanup some code. Add the…
Browse files Browse the repository at this point in the history
… ability to get the alarm time as a PMC from get_pmc_keyed_int, in case anybody wants to try that.
  • Loading branch information
Whiteknight authored and Reini Urban committed Aug 10, 2012
1 parent d752612 commit ce49c6c
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions src/pmc/alarm.pmc
Expand Up @@ -16,7 +16,9 @@ src/pmc/alarm.pmc - Alarm

=head1 DESCRIPTION

Sometime after N_time, P_sub will be called exactly once.
Sometime after N_time, P_sub will be called exactly once. Notice that due to
various factors, the alarm is not guaranteed to execute at N_time, but only
a short time thereafter. The length of "a short time" is very system dependent.

=head2 Functions

Expand All @@ -33,8 +35,8 @@ Sometime after N_time, P_sub will be called exactly once.
/* HEADERIZER END: static */

pmclass Alarm provides invokable auto_attrs {
ATTR FLOATVAL alarm_time;
ATTR PMC *alarm_task;
ATTR FLOATVAL alarm_time; /* The time when the alarm should trigger */
ATTR PMC *alarm_task; /* The Task or Sub PMC to execute */

/*

Expand Down Expand Up @@ -88,12 +90,18 @@ Returns the PMC associated with C<key>.

VTABLE PMC *get_pmc_keyed_int(INTVAL key) {
UNUSED(INTERP);
if (key == PARROT_ALARM_TASK) {
const Parrot_Alarm_attributes * const data = PARROT_ALARM(SELF);
return data->alarm_task;
}

return PMCNULL;
switch (key) {
case PARROT_ALARM_TASK:
return PARROT_ALARM(SELF)->alarm_task;
case PARROT_ALARM_TIME: {
PMC * const floatval = Parrot_pmc_new(INTERP, enum_class_Float);
VTABLE_set_number_native(INTERP, floatval, PARROT_ALARM(SELF)->alarm_time);
return floatval;
}
default:
return PMCNULL;
}
}

/*
Expand All @@ -108,10 +116,9 @@ Returns the number associated with C<key>.

VTABLE FLOATVAL get_number_keyed_int(INTVAL key) {
UNUSED(INTERP);
if (key == PARROT_ALARM_TIME) {
const Parrot_Alarm_attributes * const data = PARROT_ALARM(SELF);
return data->alarm_time;
}

if (key == PARROT_ALARM_TIME)
return PARROT_ALARM(SELF)->alarm_time;

return 0.0;
}
Expand All @@ -127,9 +134,9 @@ Having the alarm numify to the time is convienient for sorting.
*/

VTABLE FLOATVAL get_number() {
const Parrot_Alarm_attributes * const data = PARROT_ALARM(SELF);
UNUSED(INTERP);
return data->alarm_time;

return PARROT_ALARM(SELF)->alarm_time;
}

/*
Expand Down

0 comments on commit ce49c6c

Please sign in to comment.