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.115 by root, Sat May 10 21:47:28 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 &{ delete $_[0]{_ae_cb} } if $_[0]{_ae_cb}; 907 # nop
905} 908}
906 909
907sub send { 910sub send {
908 my $cv = shift; 911 my $cv = shift;
909 $cv->{_ae_sent} = [@_]; 912 $cv->{_ae_sent} = [@_];
913 (delete $cv->{_ae_cb})->($cv) if $cv->{_ae_cb};
910 $cv->_send; 914 $cv->_send;
911} 915}
912 916
913sub croak { 917sub croak {
914 $_[0]{_ae_croak} = $_[1]; 918 $_[0]{_ae_croak} = $_[1];
917 921
918sub ready { 922sub ready {
919 $_[0]{_ae_sent} 923 $_[0]{_ae_sent}
920} 924}
921 925
926sub _wait {
927 AnyEvent->one_event while !$_[0]{_ae_sent};
928}
929
922sub recv { 930sub recv {
923 AnyEvent->one_event while !$_[0]{_ae_sent}; 931 $_[0]->_wait;
924 932
925 Carp::croak $_[0]{_ae_croak} if $_[0]{_ae_croak}; 933 Carp::croak $_[0]{_ae_croak} if $_[0]{_ae_croak};
926 wantarray ? @{ $_[0]{_ae_sent} } : $_[0]{_ae_sent}[0] 934 wantarray ? @{ $_[0]{_ae_sent} } : $_[0]{_ae_sent}[0]
927} 935}
928 936
941 &{ $_[0]{_ae_end_cb} } if $_[0]{_ae_end_cb}; 949 &{ $_[0]{_ae_end_cb} } if $_[0]{_ae_end_cb};
942} 950}
943 951
944# undocumented/compatibility with pre-3.4 952# undocumented/compatibility with pre-3.4
945*broadcast = \&send; 953*broadcast = \&send;
946*wait = \&recv; 954*wait = \&_wait;
947 955
948=head1 SUPPLYING YOUR OWN EVENT MODEL INTERFACE 956=head1 SUPPLYING YOUR OWN EVENT MODEL INTERFACE
949 957
950This 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
951a 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