| 1 | # Data and accessors to manage POE's events. | ||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||
| 3 | package POE::Resource::Events; | ||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||
| 5 | 200 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 6 | 1396 | $VERSION = '1.370'; # NOTE - Should be #.### (three decimal places) | |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||
| 8 | # These methods are folded into POE::Kernel; | ||||||||||||||||||||||||||||||
| 9 | package POE::Kernel; | ||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||
| 11 | 200 | ▶ | use strict; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||
| 13 | # A local copy of the queue so we can manipulate it directly. | ||||||||||||||||||||||||||||||
| 14 | 1396 | my $kr_queue; | |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||
| 16 | my %event_count; | ||||||||||||||||||||||||||||||
| 17 | # ( $session_id => $count, | ||||||||||||||||||||||||||||||
| 18 | # ..., | ||||||||||||||||||||||||||||||
| 19 | # ); | ||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||
| 21 | 1396 | my %post_count; | |||||||||||||||||||||||||||||
| 22 | # ( $session_id => $count, | ||||||||||||||||||||||||||||||
| 23 | # ..., | ||||||||||||||||||||||||||||||
| 24 | # ); | ||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||
| 26 | ### Begin-run initialization. | ||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||
| 28 | 200 | ▶ | sub _data_ev_initialize { | ||||||||||||||||||||||||||||
|
Subroutine
_data_ev_initialize: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 29 | 200 | my ($self, $queue) = @_; | |||||||||||||||||||||||||||||
| 30 | 200 | $kr_queue = $queue; | |||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||
| 33 | ### End-run leak checking. | ||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||
| 35 | 10 | ▶ | sub _data_ev_relocate_kernel_id { | ||||||||||||||||||||||||||||
|
Subroutine
_data_ev_relocate_kernel_id: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||
| 36 | 10 | my ($self, $old_id, $new_id) = @_; | |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||
| 38 | $event_count{$new_id} = delete $event_count{$old_id} | ||||||||||||||||||||||||||||||
| 39 | 10 | ▶ | if exists $event_count{$old_id}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 40 | $post_count{$new_id} = delete $post_count{$old_id} | ||||||||||||||||||||||||||||||
| 41 | 10 | ▶ | if exists $post_count{$old_id}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||
| 44 | 204 | ▶ | sub _data_ev_finalize { | ||||||||||||||||||||||||||||
|
Subroutine
_data_ev_finalize: called CC=3 SCAR=14.2
| |||||||||||||||||||||||||||||||
| 45 | 204 | my $finalized_ok = 1; | |||||||||||||||||||||||||||||
| 46 | 204 | ▶ | while (my ($ses_id, $cnt) = each(%event_count)) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 47 | 0 | $finalized_ok = 0; | |||||||||||||||||||||||||||||
| 48 | 0 | _warn("!!! Leaked event-to count: $ses_id = $cnt\n"); | |||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||
| 51 | 204 | ▶ | while (my ($ses_id, $cnt) = each(%post_count)) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 52 | 0 | $finalized_ok = 0; | |||||||||||||||||||||||||||||
| 53 | 0 | _warn("!!! Leaked event-from count: $ses_id = $cnt\n"); | |||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||
| 55 | 204 | return $finalized_ok; | |||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||
| 58 | ### Enqueue an event. | ||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||
| 60 | sub FIFO_TIME_EPSILON () { 0.000001 } | ||||||||||||||||||||||||||||||
| 61 | 972 | my $last_fifo_time = monotime(); | |||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||
| 63 | 5394 | ▶ | sub _data_ev_enqueue { | ||||||||||||||||||||||||||||
|
Subroutine
_data_ev_enqueue: called CC=13 SCAR=25.7
| |||||||||||||||||||||||||||||||
| 64 | my ( | ||||||||||||||||||||||||||||||
| 65 | 5394 | $self, | |||||||||||||||||||||||||||||
| 66 | $session, $source_session, $event, $type, $etc, | ||||||||||||||||||||||||||||||
| 67 | $file, $line, $fromstate, $time, $delta, $priority | ||||||||||||||||||||||||||||||
| 68 | ) = @_; | ||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||
| 70 | 5394 | my $sid = $session->ID; | |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||
| 72 | 5393 | if (ASSERT_DATA) { | |||||||||||||||||||||||||||||
| 73 | unless ($self->_data_ses_exists($sid)) { | ||||||||||||||||||||||||||||||
| 74 | _trap( | ||||||||||||||||||||||||||||||
| 75 | "<ev> can't enqueue event ``$event'' for nonexistent", | ||||||||||||||||||||||||||||||
| 76 | $self->_data_alias_loggable($sid) | ||||||||||||||||||||||||||||||
| 77 | ); | ||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||
| 81 | # This is awkward, but faster than using the fields individually. | ||||||||||||||||||||||||||||||
| 82 | 5393 | my $event_to_enqueue = [ @_[(1+EV_SESSION) .. (1+EV_FROMSTATE)] ]; | |||||||||||||||||||||||||||||
| 83 | 1186 | ▶ | if( defined $time ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 84 | 4215 | $event_to_enqueue->[EV_WALLTIME] = $time; | |||||||||||||||||||||||||||||
| 85 | 4215 | $event_to_enqueue->[EV_DELTA] = $delta; | |||||||||||||||||||||||||||||
| 86 | 1515 | ▶ | $priority ||= wall2mono( $time + ($delta||0) ); | ||||||||||||||||||||||||||||
|
Condition100%5/5
$priority ||= wall2mono($time + ($delta || 0))
$delta || 0
MC/DC100%2/2
$priority ||= wall2mono($time + ($delta || 0))
$priority
wall2mono($time + ($delta || 0))
MC/DC100%1/1
$delta || 0
$delta
Truth table100%3/3
A ||= B
A= $priorityB= wall2mono($time + ($delta || 0))
Truth table100%2/2
A
A= $delta
| |||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||
| 88 | else { | ||||||||||||||||||||||||||||||
| 89 | 2685 | ▶ | $priority ||= monotime(); | ||||||||||||||||||||||||||||
|
Condition66%2/3
$priority ||= &monotime()
MC/DC0%0/2
$priority ||= &monotime()
$priority
&monotime()
Truth table66%2/3
A ||= B
A= $priorityB= &monotime()
| |||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||
| 92 | 2693 | my $new_id; | |||||||||||||||||||||||||||||
| 93 | 3886 | my $old_head_priority = $kr_queue->get_next_priority(); | |||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||
| 95 | 5393 | ▶ | unless ($type & ET_MASK_DELAYED) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 96 | 4692 | ▶ | $priority = $last_fifo_time + FIFO_TIME_EPSILON if $priority <= $last_fifo_time; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 97 | 4692 | $last_fifo_time = $priority; | |||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||
| 100 | 3416 | $new_id = $kr_queue->enqueue($priority, $event_to_enqueue); | |||||||||||||||||||||||||||||
| 101 | 3416 | $event_to_enqueue->[EV_SEQ] = $new_id; | |||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||
| 103 | #_carp( Carp::longmess( "<ev> priority is much to far in the future" ) ) if $priority > 1354569908; | ||||||||||||||||||||||||||||||
| 104 | 5393 | if (TRACE_EVENTS ) { | |||||||||||||||||||||||||||||
| 105 | _warn( | ||||||||||||||||||||||||||||||
| 106 | "<ev> enqueued event $new_id ``$event'' from ", | ||||||||||||||||||||||||||||||
| 107 | $self->_data_alias_loggable($source_session->ID), " to ", | ||||||||||||||||||||||||||||||
| 108 | $self->_data_alias_loggable($sid), | ||||||||||||||||||||||||||||||
| 109 | " at $time, priority=$priority" | ||||||||||||||||||||||||||||||
| 110 | ); | ||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||
| 113 | 5393 | ▶ | unless (defined $old_head_priority) { | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 114 | 3597 | $self->loop_resume_time_watcher($priority); | |||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||
| 116 | 4225 | elsif ($priority < $old_head_priority) { | |||||||||||||||||||||||||||||
| 117 | 4637 | $self->loop_reset_time_watcher($priority); | |||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||
| 120 | # This is the counterpart to _data_ev_refcount_dec(). It's only | ||||||||||||||||||||||||||||||
| 121 | # used in one place, so it's not in its own function. | ||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||
| 123 | 1199 | ▶ | $self->_data_ses_refcount_inc($sid) unless $event_count{$sid}++; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||
| 125 | 1801 | ▶ | return $new_id if $sid eq $source_session->ID(); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||
| 127 | $self->_data_ses_refcount_inc($source_session->ID) unless ( | ||||||||||||||||||||||||||||||
| 128 | 1589 | ▶ | $post_count{$source_session->ID}++ | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 129 | ); | ||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||
| 131 | 4307 | return $new_id; | |||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||
| 134 | sub _data_ev_set | ||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | { | ||||||||||||||||||||||||||||
|
Subroutine
_data_ev_set: not called CC=6 SCAR=30.5
| |||||||||||||||||||||||||||||||
| 136 | 3397 | my( $self, $alarm_id, $my_alarm, $time, $pri, $delta ) = @_; | |||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||
| 138 | my $event = ( | ||||||||||||||||||||||||||||||
| 139 | 215 | grep { $_->[1] == $alarm_id } | |||||||||||||||||||||||||||||
| 140 | $kr_queue->peek_items( $my_alarm ) | ||||||||||||||||||||||||||||||
| 141 | )[0]; | ||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||
| 143 | 0 | ▶ | return unless $event; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||
| 145 | 0 | my $payload = $event->[ITEM_PAYLOAD]; | |||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||
| 147 | # XXX - However, if there has been a clock skew, the priority will | ||||||||||||||||||||||||||||||
| 148 | # have changed and we should recalculate priority from time+delta | ||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | $delta = $payload->[EV_DELTA] || 0 unless defined $delta; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$payload->[10] || 0
MC/DC0%0/1
$payload->[10] || 0
$payload->[10]
Truth table0%0/2
A
A= $payload->[10]
| |||||||||||||||||||||||||||||||
| 151 | 0 | $kr_queue->set_priority( $alarm_id, $my_alarm, $pri+$delta ); | |||||||||||||||||||||||||||||
| 152 | 0 | $payload->[EV_WALLTIME] = $time; | |||||||||||||||||||||||||||||
| 153 | 0 | $payload->[EV_DELTA] = $delta; | |||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | return( ($payload->[EV_WALLTIME] || 0) + ($payload->[EV_DELTA] || 0) ); | ||||||||||||||||||||||||||||
|
Condition0%0/4
$payload->[9] || 0
$payload->[10] || 0
MC/DC0%0/1
$payload->[9] || 0
$payload->[9]
MC/DC0%0/1
$payload->[10] || 0
$payload->[10]
Truth table0%0/2
A
A= $payload->[9]
Truth table0%0/2
A
A= $payload->[10]
| |||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||
| 158 | sub _data_ev_adjust | ||||||||||||||||||||||||||||||
| 159 | 30 | ▶ | { | ||||||||||||||||||||||||||||
|
Subroutine
_data_ev_adjust: called CC=7 SCAR=20.6
| |||||||||||||||||||||||||||||||
| 160 | 30 | my( $self, $alarm_id, $my_alarm, $time, $delta ) = @_; | |||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||
| 162 | # XXX - However, if there has been a clock skew, the priority will | ||||||||||||||||||||||||||||||
| 163 | # have changed and we should recalculate priority from time+delta | ||||||||||||||||||||||||||||||
| 164 | 30 | ▶ | if( $time ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 165 | # PG - We are never invoked with $time anyway. | ||||||||||||||||||||||||||||||
| 166 | 0 | $kr_queue->set_priority( $alarm_id, $my_alarm, $time+$delta ); | |||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||
| 168 | else { | ||||||||||||||||||||||||||||||
| 169 | 30 | $kr_queue->adjust_priority( $alarm_id, $my_alarm, $delta ); | |||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||
| 172 | my $event = ( | ||||||||||||||||||||||||||||||
| 173 | 30 | grep { $_->[1] == $alarm_id } | |||||||||||||||||||||||||||||
| 174 | $kr_queue->peek_items( $my_alarm ) | ||||||||||||||||||||||||||||||
| 175 | )[0]; | ||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||
| 177 | 30 | ▶ | return unless $event; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||
| 179 | 30 | my $payload = $event->[ITEM_PAYLOAD]; | |||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||
| 181 | 30 | ▶ | $payload->[EV_WALLTIME] = $time if $time; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 182 | 30 | ▶ | $payload->[EV_DELTA] += $delta if $delta; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||
| 184 | 30 | ▶ | return( ($payload->[EV_WALLTIME] || 0) + ($payload->[EV_DELTA] || 0) ); | ||||||||||||||||||||||||||||
|
Condition75%3/4
$payload->[9] || 0
$payload->[10] || 0
MC/DC0%0/1
$payload->[9] || 0
$payload->[9]
MC/DC100%1/1
$payload->[10] || 0
$payload->[10]
Truth table50%1/2
A
A= $payload->[9]
Truth table100%2/2
A
A= $payload->[10]
| |||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||
| 187 | ### Remove events sent to or from a specific session. | ||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||
| 189 | 818 | ▶ | sub _data_ev_clear_session { | ||||||||||||||||||||||||||||
|
Subroutine
_data_ev_clear_session: called CC=11 SCAR=25.7
| |||||||||||||||||||||||||||||||
| 190 | 818 | my ($self, $sid) = @_; | |||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||
| 192 | # Events sent to the session. | ||||||||||||||||||||||||||||||
| 193 | PENDING: { | ||||||||||||||||||||||||||||||
| 194 | 818 | my $pending_count = $event_count{$sid}; | |||||||||||||||||||||||||||||
| 195 | 818 | ▶ | last PENDING unless $pending_count; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||
| 197 | 235 | foreach ( | |||||||||||||||||||||||||||||
| 198 | $kr_queue->remove_items( | ||||||||||||||||||||||||||||||
| 199 | 257 | ▶ | sub { $_[0][EV_SESSION]->ID() eq $sid }, | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 200 | $pending_count | ||||||||||||||||||||||||||||||
| 201 | ) | ||||||||||||||||||||||||||||||
| 202 | ) { | ||||||||||||||||||||||||||||||
| 203 | $self->_data_ev_refcount_dec( | ||||||||||||||||||||||||||||||
| 204 | 240 | @{$_->[ITEM_PAYLOAD]}[EV_SOURCE, EV_SESSION] | |||||||||||||||||||||||||||||
| 205 | ); | ||||||||||||||||||||||||||||||
| 206 | 240 | $pending_count--; | |||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||
| 209 | # TODO - fork() can make this go negative on some systems. | ||||||||||||||||||||||||||||||
| 210 | 235 | ▶ | last PENDING unless $pending_count; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||
| 212 | 0 | ▶ | croak "lingering pending count: $pending_count" if $pending_count; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||
| 215 | # Events sent by the session. | ||||||||||||||||||||||||||||||
| 216 | SENT: { | ||||||||||||||||||||||||||||||
| 217 | 818 | my $sent_count = $post_count{$sid}; | |||||||||||||||||||||||||||||
| 218 | 818 | ▶ | last SENT unless $sent_count; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||
| 220 | 3 | foreach ( | |||||||||||||||||||||||||||||
| 221 | $kr_queue->remove_items( | ||||||||||||||||||||||||||||||
| 222 | 3 | ▶ | sub { $_[0][EV_SOURCE]->ID() eq $sid }, | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 223 | $sent_count | ||||||||||||||||||||||||||||||
| 224 | ) | ||||||||||||||||||||||||||||||
| 225 | ) { | ||||||||||||||||||||||||||||||
| 226 | $self->_data_ev_refcount_dec( | ||||||||||||||||||||||||||||||
| 227 | 3 | @{$_->[ITEM_PAYLOAD]}[EV_SOURCE, EV_SESSION] | |||||||||||||||||||||||||||||
| 228 | ); | ||||||||||||||||||||||||||||||
| 229 | 3 | $sent_count--; | |||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||
| 232 | 3 | ▶ | last SENT unless $sent_count; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||
| 234 | 0 | ▶ | croak "lingering sent count: $sent_count" if $sent_count; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||
| 237 | 818 | ▶ | croak "lingering event count" if delete $event_count{$sid}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 238 | 818 | ▶ | croak "lingering post count" if delete $post_count{$sid}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||
| 241 | # TODO Alarm maintenance functions may move out to a separate | ||||||||||||||||||||||||||||||
| 242 | # POE::Resource module in the future. Why? Because alarms may | ||||||||||||||||||||||||||||||
| 243 | # eventually be managed by something other than the event queue. | ||||||||||||||||||||||||||||||
| 244 | # Especially if we incorporate a proper Session scheduler. Be sure to | ||||||||||||||||||||||||||||||
| 245 | # move the tests to a corresponding t/res/*.t file. | ||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||
| 247 | ### Remove a specific alarm by its name. This is in the events | ||||||||||||||||||||||||||||||
| 248 | ### section because alarms are currently implemented as events with | ||||||||||||||||||||||||||||||
| 249 | ### future due times. | ||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||
| 251 | 3456 | ▶ | sub _data_ev_clear_alarm_by_name { | ||||||||||||||||||||||||||||
|
Subroutine
_data_ev_clear_alarm_by_name: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 252 | 3456 | my ($self, $sid, $alarm_name) = @_; | |||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||
| 254 | 798818 | ▶ | my $my_alarm = sub { | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||
| 255 | 798818 | ▶ | return 0 unless $_[0]->[EV_TYPE] & ET_ALARM; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 256 | 795933 | ▶ | return 0 unless $_[0]->[EV_SESSION]->ID() eq $sid; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 257 | 793004 | ▶ | return 0 unless $_[0]->[EV_NAME] eq $alarm_name; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 258 | 1382 | return 1; | |||||||||||||||||||||||||||||
| 259 | 3456 | }; | |||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||
| 261 | 3456 | foreach ($kr_queue->remove_items($my_alarm)) { | |||||||||||||||||||||||||||||
| 262 | 1382 | $self->_data_ev_refcount_dec(@{$_->[ITEM_PAYLOAD]}[EV_SOURCE, EV_SESSION]); | |||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||
| 266 | ### Remove a specific alarm by its ID. This is in the events section | ||||||||||||||||||||||||||||||
| 267 | ### because alarms are currently implemented as events with future due | ||||||||||||||||||||||||||||||
| 268 | ### times. TODO It's possible to remove non-alarms; is that wrong? | ||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||
| 270 | 229 | ▶ | sub _data_ev_clear_alarm_by_id { | ||||||||||||||||||||||||||||
|
Subroutine
_data_ev_clear_alarm_by_id: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||
| 271 | 229 | my ($self, $sid, $alarm_id) = @_; | |||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||
| 273 | 228 | ▶ | my $my_alarm = sub { | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 274 | 445 | $_[0]->[EV_SESSION]->ID() eq $sid; | |||||||||||||||||||||||||||||
| 275 | 229 | }; | |||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||
| 277 | 229 | my ($pri, $id, $event) = $kr_queue->remove_item($alarm_id, $my_alarm); | |||||||||||||||||||||||||||||
| 278 | 229 | ▶ | return unless defined $pri; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||
| 280 | 228 | if (TRACE_EVENTS) { | |||||||||||||||||||||||||||||
| 281 | _warn( | ||||||||||||||||||||||||||||||
| 282 | "<ev> removed event $id ``", $event->[EV_NAME], "'' to ", | ||||||||||||||||||||||||||||||
| 283 | $self->_data_alias_loggable($sid), " at $pri" | ||||||||||||||||||||||||||||||
| 284 | ); | ||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||
| 287 | 228 | $self->_data_ev_refcount_dec( @$event[EV_SOURCE, EV_SESSION] ); | |||||||||||||||||||||||||||||
| 288 | 228 | ▶ | my $time = $event->[EV_WALLTIME] + ($event->[EV_DELTA]||0); | ||||||||||||||||||||||||||||
|
Condition100%2/2
$event->[10] || 0
MC/DC100%1/1
$event->[10] || 0
$event->[10]
Truth table100%2/2
A
A= $event->[10]
| |||||||||||||||||||||||||||||||
| 289 | 228 | return ($time, $event); | |||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||
| 292 | ### Remove all the alarms for a session. Whoot! | ||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||
| 294 | 4 | ▶ | sub _data_ev_clear_alarm_by_session { | ||||||||||||||||||||||||||||
|
Subroutine
_data_ev_clear_alarm_by_session: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||
| 295 | 4 | my ($self, $sid) = @_; | |||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||
| 297 | 30 | ▶ | my $my_alarm = sub { | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||
| 298 | 30 | ▶ | return 0 unless $_[0]->[EV_TYPE] & ET_ALARM; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 299 | 26 | ▶ | return 0 unless $_[0]->[EV_SESSION]->ID() eq $sid; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 300 | 5 | return 1; | |||||||||||||||||||||||||||||
| 301 | 4 | }; | |||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||
| 303 | 4 | my @removed; | |||||||||||||||||||||||||||||
| 304 | 4 | foreach ($kr_queue->remove_items($my_alarm)) { | |||||||||||||||||||||||||||||
| 305 | 5 | my ($pri, $event) = @$_[ITEM_PRIORITY, ITEM_PAYLOAD]; | |||||||||||||||||||||||||||||
| 306 | 5 | $self->_data_ev_refcount_dec( @$event[EV_SOURCE, EV_SESSION] ); | |||||||||||||||||||||||||||||
| 307 | 5 | ▶ | my $time = ($event->[EV_WALLTIME]||0) + ($event->[EV_DELTA]||0); | ||||||||||||||||||||||||||||
|
Condition75%3/4
$event->[9] || 0
$event->[10] || 0
MC/DC100%1/1
$event->[9] || 0
$event->[9]
MC/DC0%0/1
$event->[10] || 0
$event->[10]
Truth table100%2/2
A
A= $event->[9]
Truth table50%1/2
A
A= $event->[10]
| |||||||||||||||||||||||||||||||
| 308 | 5 | push @removed, [ $event->[EV_NAME], $time, @{$event->[EV_ARGS]} ]; | |||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||
| 311 | 4 | return @removed; | |||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||
| 314 | ### Decrement a post refcount | ||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||
| 316 | 5231 | ▶ | sub _data_ev_refcount_dec { | ||||||||||||||||||||||||||||
|
Subroutine
_data_ev_refcount_dec: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||
| 317 | 5231 | my ($self, $source_session, $dest_session) = @_; | |||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||
| 319 | 5231 | my ($source_id, $dest_id) = ($source_session->ID, $dest_session->ID); | |||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||
| 321 | 5231 | if (ASSERT_DATA) { | |||||||||||||||||||||||||||||
| 322 | _trap $dest_session unless exists $event_count{$dest_id}; | ||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||
| 325 | 5231 | ▶ | $self->_data_ses_refcount_dec($dest_id) unless --$event_count{$dest_id}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||
| 327 | 5231 | ▶ | return if $dest_id eq $source_id; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||
| 329 | 4174 | if (ASSERT_DATA) { | |||||||||||||||||||||||||||||
| 330 | _trap $source_session unless exists $post_count{$source_id}; | ||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||
| 333 | 315 | ▶ | $self->_data_ses_refcount_dec($source_id) unless --$post_count{$source_id}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||
| 336 | ### Fetch the number of pending events sent to a session. | ||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||
| 338 | 4822 | ▶ | sub _data_ev_get_count_to { | ||||||||||||||||||||||||||||
|
Subroutine
_data_ev_get_count_to: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 339 | 5037 | my ($self, $sid) = @_; | |||||||||||||||||||||||||||||
| 340 | 5037 | ▶ | return $event_count{$sid} || 0; | ||||||||||||||||||||||||||||
|
Condition100%2/2
$event_count{$sid} || 0
MC/DC100%1/1
$event_count{$sid} || 0
$event_count{$sid}
Truth table100%2/2
A
A= $event_count{$sid}
| |||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||
| 343 | ### Fetch the number of pending events sent from a session. | ||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||
| 345 | 4820 | ▶ | sub _data_ev_get_count_from { | ||||||||||||||||||||||||||||
|
Subroutine
_data_ev_get_count_from: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 346 | 4820 | my ($self, $sid) = @_; | |||||||||||||||||||||||||||||
| 347 | 4820 | ▶ | return $post_count{$sid} || 0; | ||||||||||||||||||||||||||||
|
Condition100%2/2
$post_count{$sid} || 0
MC/DC100%1/1
$post_count{$sid} || 0
$post_count{$sid}
Truth table100%2/2
A
A= $post_count{$sid}
| |||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||
| 350 | ### Dispatch events that are due for "now" or earlier. | ||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||
| 352 | 2598 | ▶ | sub _data_ev_dispatch_due { | ||||||||||||||||||||||||||||
|
Subroutine
_data_ev_dispatch_due: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||
| 353 | 2598 | my $self = shift; | |||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||
| 355 | 2598 | if (TRACE_EVENTS) { | |||||||||||||||||||||||||||||
| 356 | 2366 | ▶ | foreach ($kr_queue->peek_items(sub { 1 })) { | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 357 | my @event = map { defined() ? $_ : "(undef)" } @{$_->[ITEM_PAYLOAD]}; | ||||||||||||||||||||||||||||||
| 358 | _warn( | ||||||||||||||||||||||||||||||
| 359 | "<ev> time($_->[ITEM_PRIORITY]) id($_->[ITEM_ID]) ", | ||||||||||||||||||||||||||||||
| 360 | "event(@event)\n" | ||||||||||||||||||||||||||||||
| 361 | ); | ||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||
| 365 | 2598 | my $now = monotime(); | |||||||||||||||||||||||||||||
| 366 | 3768 | my $next_time; | |||||||||||||||||||||||||||||
| 367 | 22742 | ▶ | while ( | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined($next_time = $kr_queue->get_next_priority) and $next_time <= $now
MC/DC100%2/2
defined($next_time = $kr_queue->get_next_priority) and $next_time <= $now
defined($next_time = $kr_queue->get_next_priority)
$next_time <= $now
Truth table100%3/3
A and B
A= defined($next_time = $kr_queue->get_next_priority)B= $next_time <= $now
| |||||||||||||||||||||||||||||||
| 368 | defined($next_time = $kr_queue->get_next_priority()) and | ||||||||||||||||||||||||||||||
| 369 | $next_time <= $now | ||||||||||||||||||||||||||||||
| 370 | ) { | ||||||||||||||||||||||||||||||
| 371 | 4112 | my ($priority, $id, $event) = $kr_queue->dequeue_next(); | |||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||
| 373 | 4112 | if (TRACE_EVENTS) { | |||||||||||||||||||||||||||||
| 374 | _warn("<ev> dispatching event $id ($event->[EV_NAME])"); | ||||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||
| 377 | # TODO - Why can't we reverse these two lines? | ||||||||||||||||||||||||||||||
| 378 | # TODO - Reversing them could avoid entering and removing GC marks. | ||||||||||||||||||||||||||||||
| 379 | 2942 | $self->_data_ev_refcount_dec($event->[EV_SOURCE], $event->[EV_SESSION]); | |||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||
| 381 | 2942 | ▶ | if ($event->[EV_TYPE] & (ET_SIGNAL | ET_SIGDIE)) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 382 | 1489 | $self->_dispatch_signal_event(@{$event}[EV_SESSION..EV_FROMSTATE], $priority, $id); | |||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||
| 384 | else { | ||||||||||||||||||||||||||||||
| 385 | 3080 | $self->_dispatch_event(@{$event}[EV_SESSION..EV_FROMSTATE], $priority, $id); | |||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||
| 388 | # Stop the system if an unhandled exception occurred. | ||||||||||||||||||||||||||||||
| 389 | # This wipes out all sessions and associated resources. | ||||||||||||||||||||||||||||||
| 390 | 3362 | ▶ | next unless $POE::Kernel::kr_exception; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 391 | 1642 | POE::Kernel->stop(); | |||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||
| 394 | # Sweep for dead sessions. The sweep may alter the next queue time. | ||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||
| 396 | 1593 | $self->_data_ses_gc_sweep(); | |||||||||||||||||||||||||||||
| 397 | 1593 | $next_time = $kr_queue->get_next_priority(); | |||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||
| 399 | # Tell the event loop to wait for the next event, if there is one. | ||||||||||||||||||||||||||||||
| 400 | # Otherwise we're going to wait indefinitely for some other event. | ||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||
| 402 | 2816 | ▶ | if (defined $next_time) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 403 | 2300 | $self->loop_reset_time_watcher($next_time); | |||||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||||
| 405 | else { | ||||||||||||||||||||||||||||||
| 406 | 2143 | $self->loop_pause_time_watcher(); | |||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||
| 410 | 624 | 1; | |||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||
| 412 | __END__ | ||||||||||||||||||||||||||||||