ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/Coro.pm
(Generate patch)

Comparing Coro/Coro.pm (file contents):
Revision 1.316 by root, Wed Mar 6 06:00:08 2013 UTC vs.
Revision 1.322 by root, Tue Mar 4 05:07:34 2014 UTC

366 366
367our $idle; # idle handler 367our $idle; # idle handler
368our $main; # main coro 368our $main; # main coro
369our $current; # current coro 369our $current; # current coro
370 370
371our $VERSION = 6.28; 371our $VERSION = 6.33;
372 372
373our @EXPORT = qw(async async_pool cede schedule terminate current unblock_sub rouse_cb rouse_wait); 373our @EXPORT = qw(async async_pool cede schedule terminate current unblock_sub rouse_cb rouse_wait);
374our %EXPORT_TAGS = ( 374our %EXPORT_TAGS = (
375 prio => [qw(PRIO_MAX PRIO_HIGH PRIO_NORMAL PRIO_LOW PRIO_IDLE PRIO_MIN)], 375 prio => [qw(PRIO_MAX PRIO_HIGH PRIO_NORMAL PRIO_LOW PRIO_IDLE PRIO_MIN)],
376); 376);
652 Coro::on_enter { 652 Coro::on_enter {
653 # on entering the thread, we set an VTALRM handler to cede 653 # on entering the thread, we set an VTALRM handler to cede
654 $SIG{VTALRM} = sub { cede }; 654 $SIG{VTALRM} = sub { cede };
655 # and then start the interval timer 655 # and then start the interval timer
656 Time::HiRes::setitimer &Time::HiRes::ITIMER_VIRTUAL, 0.01, 0.01; 656 Time::HiRes::setitimer &Time::HiRes::ITIMER_VIRTUAL, 0.01, 0.01;
657 }; 657 };
658 Coro::on_leave { 658 Coro::on_leave {
659 # on leaving the thread, we stop the interval timer again 659 # on leaving the thread, we stop the interval timer again
660 Time::HiRes::setitimer &Time::HiRes::ITIMER_VIRTUAL, 0, 0; 660 Time::HiRes::setitimer &Time::HiRes::ITIMER_VIRTUAL, 0, 0;
661 }; 661 };
662 662
663 &{+shift}; 663 &{+shift};
664 } 664 }
665 665
666 # use like this: 666 # use like this:
667 timeslice { 667 timeslice {
668 # The following is an endless loop that would normally 668 # The following is an endless loop that would normally
669 # monopolise the process. Since it runs in a timesliced 669 # monopolise the process. Since it runs in a timesliced
670 # environment, it will regularly cede to other threads. 670 # environment, it will regularly cede to other threads.
671 while () { } 671 while () { }
672 }; 672 };
673 673
674 674
675=item killall 675=item killall
676 676
677Kills/terminates/cancels all coros except the currently running one. 677Kills/terminates/cancels all coros except the currently running one.
914that is, after it's resources have been freed but before it is joined. The 914that is, after it's resources have been freed but before it is joined. The
915callback gets passed the terminate/cancel arguments, if any, and I<must 915callback gets passed the terminate/cancel arguments, if any, and I<must
916not> die, under any circumstances. 916not> die, under any circumstances.
917 917
918There can be any number of C<on_destroy> callbacks per coro, and there is 918There can be any number of C<on_destroy> callbacks per coro, and there is
919no way currently to remove a callback once added. 919currently no way to remove a callback once added.
920 920
921=item $oldprio = $coro->prio ($newprio) 921=item $oldprio = $coro->prio ($newprio)
922 922
923Sets (or gets, if the argument is missing) the priority of the 923Sets (or gets, if the argument is missing) the priority of the
924coro thread. Higher priority coro get run before lower priority 924coro thread. Higher priority coro get run before lower priority

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines