--- Coro/Coro.pm 2007/09/21 01:23:58 1.133 +++ Coro/Coro.pm 2007/09/22 14:42:56 1.134 @@ -229,37 +229,39 @@ 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); - }; - warn $@ if $@; + while () { + $cb = &_pool_1 + or return; - last if @pool >= $POOL_SIZE || $current->rss >= $MAX_POOL_RSS; + &$cb; - push @pool, $current; - $current->{desc} = "[async_pool idle]"; - $current->save (Coro::State::SAVE_DEF); - $current->prio (0); - schedule; + return if &_pool_2; + + undef $cb; + schedule; + } + }; + + 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;