… | |
… | |
322 | }; |
322 | }; |
323 | $TICK_WATCHER->stop; |
323 | $TICK_WATCHER->stop; |
324 | $guard |
324 | $guard |
325 | } |
325 | } |
326 | |
326 | |
|
|
327 | =item cf::get_slot $time[, $priority[, $name]] |
|
|
328 | |
|
|
329 | Allocate $time seconds of blocking CPU time at priority C<$priority>: |
|
|
330 | This call blocks and returns only when you have at least C<$time> seconds |
|
|
331 | of cpu time till the next tick. The slot is only valid till the next cede. |
|
|
332 | |
|
|
333 | The optional C<$name> can be used to identify the job to run. It might be |
|
|
334 | used for statistical purposes and should identify the same time-class. |
|
|
335 | |
|
|
336 | Useful for short background jobs. |
|
|
337 | |
|
|
338 | =cut |
|
|
339 | |
|
|
340 | our @SLOT_QUEUE; |
|
|
341 | our $SLOT_QUEUE; |
|
|
342 | |
|
|
343 | $SLOT_QUEUE->cancel if $SLOT_QUEUE; |
|
|
344 | $SLOT_QUEUE = Coro::async { |
|
|
345 | my $signal = new Coro::Signal; |
|
|
346 | |
|
|
347 | while () { |
|
|
348 | next_job: |
|
|
349 | my $avail = cf::till_tick; |
|
|
350 | if ($avail > 0.01) { |
|
|
351 | for (0 .. $#SLOT_QUEUE) { |
|
|
352 | if ($SLOT_QUEUE[$_][0] < $avail) { |
|
|
353 | my $job = splice @SLOT_QUEUE, $_, 1, (); |
|
|
354 | $job->[2]->send; |
|
|
355 | Coro::cede; |
|
|
356 | goto next_job; |
|
|
357 | } |
|
|
358 | } |
|
|
359 | } |
|
|
360 | |
|
|
361 | if (@SLOT_QUEUE) { |
|
|
362 | # we do not use wait_For_tick() as it returns immediately when tick is inactive |
|
|
363 | push @cf::WAIT_FOR_TICK, $signal; |
|
|
364 | $signal->wait; |
|
|
365 | } else { |
|
|
366 | Coro::schedule; |
|
|
367 | } |
|
|
368 | } |
|
|
369 | }; |
|
|
370 | |
|
|
371 | sub get_slot($;$$) { |
|
|
372 | my ($time, $pri, $name) = @_; |
|
|
373 | |
|
|
374 | $time = $TICK * .6 if $time > $TICK * .6; |
|
|
375 | my $sig = new Coro::Signal; |
|
|
376 | |
|
|
377 | push @SLOT_QUEUE, [$time, $pri, $sig, $name]; |
|
|
378 | @SLOT_QUEUE = sort { $b->[1] <=> $a->[1] } @SLOT_QUEUE; |
|
|
379 | $SLOT_QUEUE->ready; |
|
|
380 | $sig->wait; |
|
|
381 | } |
|
|
382 | |
327 | =item cf::async { BLOCK } |
383 | =item cf::async { BLOCK } |
328 | |
384 | |
329 | Currently the same as Coro::async_pool, meaning you cannot use |
385 | Currently the same as Coro::async_pool, meaning you cannot use |
330 | C<on_destroy>, C<join> or other gimmicks on these coroutines. The only |
386 | C<on_destroy>, C<join> or other gimmicks on these coroutines. The only |
331 | thing you are allowed to do is call C<prio> on it. |
387 | thing you are allowed to do is call C<prio> on it. |
… | |
… | |
918 | |
974 | |
919 | =cut |
975 | =cut |
920 | |
976 | |
921 | ############################################################################# |
977 | ############################################################################# |
922 | # object support |
978 | # object support |
|
|
979 | # |
|
|
980 | |
|
|
981 | sub _can_merge { |
|
|
982 | my ($ob1, $ob2) = @_; |
|
|
983 | |
|
|
984 | local $Storable::canonical = 1; |
|
|
985 | my $fob1 = Storable::freeze $ob1; |
|
|
986 | my $fob2 = Storable::freeze $ob2; |
|
|
987 | |
|
|
988 | $fob1 eq $fob2 |
|
|
989 | } |
923 | |
990 | |
924 | sub reattach { |
991 | sub reattach { |
925 | # basically do the same as instantiate, without calling instantiate |
992 | # basically do the same as instantiate, without calling instantiate |
926 | my ($obj) = @_; |
993 | my ($obj) = @_; |
927 | |
994 | |
… | |
… | |
2439 | sub cf::client::send_msg { |
2506 | sub cf::client::send_msg { |
2440 | my ($self, $channel, $msg, $color, @extra) = @_; |
2507 | my ($self, $channel, $msg, $color, @extra) = @_; |
2441 | |
2508 | |
2442 | $msg = $self->pl->expand_cfpod ($msg); |
2509 | $msg = $self->pl->expand_cfpod ($msg); |
2443 | |
2510 | |
2444 | return unless @extra || length $msg; |
|
|
2445 | |
|
|
2446 | $color &= ~cf::NDI_UNIQUE; # just in case... |
2511 | $color &= ~cf::NDI_UNIQUE; # just in case... |
2447 | |
2512 | |
2448 | if (ref $channel) { |
2513 | if (ref $channel) { |
2449 | # send meta info to client, if not yet sent |
2514 | # send meta info to client, if not yet sent |
2450 | unless (exists $self->{channel}{$channel->{id}}) { |
2515 | unless (exists $self->{channel}{$channel->{id}}) { |
… | |
… | |
2452 | $self->ext_event (channel_info => %$channel); |
2517 | $self->ext_event (channel_info => %$channel); |
2453 | } |
2518 | } |
2454 | |
2519 | |
2455 | $channel = $channel->{id}; |
2520 | $channel = $channel->{id}; |
2456 | } |
2521 | } |
|
|
2522 | |
|
|
2523 | return unless @extra || length $msg; |
2457 | |
2524 | |
2458 | if ($self->can_msg) { |
2525 | if ($self->can_msg) { |
2459 | $self->send_packet ("msg " . $self->{json_coder}->encode ([$color, $channel, $msg, @extra])); |
2526 | $self->send_packet ("msg " . $self->{json_coder}->encode ([$color, $channel, $msg, @extra])); |
2460 | } else { |
2527 | } else { |
2461 | # replace some tags by gcfclient-compatible ones |
2528 | # replace some tags by gcfclient-compatible ones |