--- AnyEvent/lib/AnyEvent.pm 2008/05/10 21:12:49 1.114 +++ AnyEvent/lib/AnyEvent.pm 2008/05/11 17:54:13 1.117 @@ -693,7 +693,7 @@ use Carp; -our $VERSION = '3.4'; +our $VERSION = '3.41'; our $MODEL; our $AUTOLOAD; @@ -813,7 +813,7 @@ # default implementation for ->condvar sub condvar { - bless {}, "AnyEvent::Base::CondVar" + bless {}, AnyEvent::CondVar:: } # default implementation for ->signal @@ -897,20 +897,25 @@ undef $CHLD_W unless keys %PID_CB; } -package AnyEvent::Base::CondVar; +package AnyEvent::CondVar; + +our @ISA = AnyEvent::CondVar::Base::; + +package AnyEvent::CondVar::Base; -# wake up the waiter sub _send { - &{ $_[0]{_ae_cb} } if $_[0]{_ae_cb}; + # nop } sub send { - $_[0]{_ae_sent} = [@_]; - $_[0]->_send; + my $cv = shift; + $cv->{_ae_sent} = [@_]; + (delete $cv->{_ae_cb})->($cv) if $cv->{_ae_cb}; + $cv->_send; } sub croak { - $_[0]{_ae_croak} = $_[0]; + $_[0]{_ae_croak} = $_[1]; $_[0]->send; } @@ -918,8 +923,12 @@ $_[0]{_ae_sent} } -sub recv { +sub _wait { AnyEvent->one_event while !$_[0]{_ae_sent}; +} + +sub recv { + $_[0]->_wait; Carp::croak $_[0]{_ae_croak} if $_[0]{_ae_croak}; wantarray ? @{ $_[0]{_ae_sent} } : $_[0]{_ae_sent}[0] @@ -942,7 +951,7 @@ # undocumented/compatibility with pre-3.4 *broadcast = \&send; -*wait = \&recv; +*wait = \&_wait; =head1 SUPPLYING YOUR OWN EVENT MODEL INTERFACE