… | |
… | |
691 | no warnings; |
691 | no warnings; |
692 | use strict; |
692 | use strict; |
693 | |
693 | |
694 | use Carp; |
694 | use Carp; |
695 | |
695 | |
696 | our $VERSION = '3.4'; |
696 | our $VERSION = '3.41'; |
697 | our $MODEL; |
697 | our $MODEL; |
698 | |
698 | |
699 | our $AUTOLOAD; |
699 | our $AUTOLOAD; |
700 | our @ISA; |
700 | our @ISA; |
701 | |
701 | |
… | |
… | |
811 | package AnyEvent::Base; |
811 | package AnyEvent::Base; |
812 | |
812 | |
813 | # default implementation for ->condvar |
813 | # default implementation for ->condvar |
814 | |
814 | |
815 | sub condvar { |
815 | sub 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 | |
821 | our %SIG_CB; |
821 | our %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 | |
900 | package AnyEvent::Base::CondVar; |
900 | package AnyEvent::CondVar; |
901 | |
901 | |
902 | # wake up the waiter |
902 | our @ISA = AnyEvent::CondVar::Base::; |
|
|
903 | |
|
|
904 | package AnyEvent::CondVar::Base; |
|
|
905 | |
903 | sub _send { |
906 | sub _send { |
904 | &{ delete $_[0]{_ae_cb} } if $_[0]{_ae_cb}; |
907 | # nop |
905 | } |
908 | } |
906 | |
909 | |
907 | sub send { |
910 | sub 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 | |
913 | sub croak { |
917 | sub croak { |
914 | $_[0]{_ae_croak} = $_[1]; |
918 | $_[0]{_ae_croak} = $_[1]; |
… | |
… | |
917 | |
921 | |
918 | sub ready { |
922 | sub ready { |
919 | $_[0]{_ae_sent} |
923 | $_[0]{_ae_sent} |
920 | } |
924 | } |
921 | |
925 | |
|
|
926 | sub _wait { |
|
|
927 | AnyEvent->one_event while !$_[0]{_ae_sent}; |
|
|
928 | } |
|
|
929 | |
922 | sub recv { |
930 | sub 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 | |
950 | This is an advanced topic that you do not normally need to use AnyEvent in |
958 | This is an advanced topic that you do not normally need to use AnyEvent in |
951 | a module. This section is only of use to event loop authors who want to |
959 | a module. This section is only of use to event loop authors who want to |