--- Coro/Coro.pm 2007/09/21 01:23:58 1.133 +++ Coro/Coro.pm 2007/09/26 19:26:48 1.137 @@ -157,6 +157,10 @@ for @{(delete $self->{destroy_cb}) || []}; } +sub _do_trace { + $current->{_trace_cb}->(); +} + # this coroutine is necessary because a coroutine # cannot destroy itself. my @destroy; @@ -229,37 +233,35 @@ single C used a lot of stackspace you can e.g. C once per second or so to slowly replenish the pool. In addition to that, when the stacks used by a handler grows larger than 16kb -(adjustable with $Coro::MAX_POOL_RSS) it will also exit. +(adjustable with $Coro::POOL_RSS) it will also exit. =cut our $POOL_SIZE = 8; -our $MAX_POOL_RSS = 16 * 1024; -our @pool; +our $POOL_RSS = 16 * 1024; +our @async_pool; sub pool_handler { - while () { - $current->{desc} = "[async_pool]"; + my $cb; + while () { eval { - my ($cb, @arg) = @{ delete $current->{_invoke} or return }; - $cb->(@arg); + while () { + _pool_1 $cb; + &$cb; + _pool_2 $cb; + &schedule; + } }; - warn $@ if $@; - - last if @pool >= $POOL_SIZE || $current->rss >= $MAX_POOL_RSS; - push @pool, $current; - $current->{desc} = "[async_pool idle]"; - $current->save (Coro::State::SAVE_DEF); - $current->prio (0); - schedule; + last if $@ eq "\3terminate\2\n"; + warn $@ if $@; } } sub async_pool(&@) { # this is also inlined into the unlock_scheduler - my $coro = (pop @pool) || new Coro \&pool_handler;; + my $coro = (pop @async_pool) || new Coro \&pool_handler; $coro->{_invoke} = [@_]; $coro->ready; @@ -539,7 +541,7 @@ while () { while (my $cb = pop @unblock_queue) { # this is an inlined copy of async_pool - my $coro = (pop @pool or new Coro \&pool_handler); + my $coro = (pop @async_pool) || new Coro \&pool_handler; $coro->{_invoke} = $cb; $coro->ready;