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

Comparing AnyEvent/lib/AnyEvent.pm (file contents):
Revision 1.114 by root, Sat May 10 21:12:49 2008 UTC vs.
Revision 1.116 by root, Sat May 10 22:30:28 2008 UTC

811package AnyEvent::Base; 811package AnyEvent::Base;
812 812
813# default implementation for ->condvar 813# default implementation for ->condvar
814 814
815sub condvar { 815sub condvar {
816 bless {}, "AnyEvent::Base::CondVar" 816 bless {}, AnyEvent::CondVar::
817} 817}
818 818
819# default implementation for ->signal 819# default implementation for ->signal
820 820
821our %SIG_CB; 821our %SIG_CB;
895 delete $PID_CB{$pid} unless keys %{ $PID_CB{$pid} }; 895 delete $PID_CB{$pid} unless keys %{ $PID_CB{$pid} };
896 896
897 undef $CHLD_W unless keys %PID_CB; 897 undef $CHLD_W unless keys %PID_CB;
898} 898}
899 899
900package AnyEvent::Base::CondVar; 900package AnyEvent::CondVar;
901 901
902# wake up the waiter 902our @ISA = AnyEvent::CondVar::Base::;
903
904package AnyEvent::CondVar::Base;
905
903sub _send { 906sub _send {
904 &{ $_[0]{_ae_cb} } if $_[0]{_ae_cb}; 907 # nop
905} 908}
906 909
907sub send { 910sub send {
911 my $cv = shift;
908 $_[0]{_ae_sent} = [@_]; 912 $cv->{_ae_sent} = [@_];
913 (delete $cv->{_ae_cb})->($cv) if $cv->{_ae_cb};
909 $_[0]->_send; 914 $cv->_send;
910} 915}
911 916
912sub croak { 917sub croak {
913 $_[0]{_ae_croak} = $_[0]; 918 $_[0]{_ae_croak} = $_[1];
914 $_[0]->send; 919 $_[0]->send;
915} 920}
916 921
917sub ready { 922sub ready {
918 $_[0]{_ae_sent} 923 $_[0]{_ae_sent}
919} 924}
920 925
926sub _wait {
927 AnyEvent->one_event while !$_[0]{_ae_sent};
928}
929
921sub recv { 930sub recv {
922 AnyEvent->one_event while !$_[0]{_ae_sent}; 931 $_[0]->_wait;
923 932
924 Carp::croak $_[0]{_ae_croak} if $_[0]{_ae_croak}; 933 Carp::croak $_[0]{_ae_croak} if $_[0]{_ae_croak};
925 wantarray ? @{ $_[0]{_ae_sent} } : $_[0]{_ae_sent}[0] 934 wantarray ? @{ $_[0]{_ae_sent} } : $_[0]{_ae_sent}[0]
926} 935}
927 936
940 &{ $_[0]{_ae_end_cb} } if $_[0]{_ae_end_cb}; 949 &{ $_[0]{_ae_end_cb} } if $_[0]{_ae_end_cb};
941} 950}
942 951
943# undocumented/compatibility with pre-3.4 952# undocumented/compatibility with pre-3.4
944*broadcast = \&send; 953*broadcast = \&send;
945*wait = \&recv; 954*wait = \&_wait;
946 955
947=head1 SUPPLYING YOUR OWN EVENT MODEL INTERFACE 956=head1 SUPPLYING YOUR OWN EVENT MODEL INTERFACE
948 957
949This is an advanced topic that you do not normally need to use AnyEvent in 958This is an advanced topic that you do not normally need to use AnyEvent in
950a module. This section is only of use to event loop authors who want to 959a module. This section is only of use to event loop authors who want to

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines