--- deliantra/server/lib/cf.pm 2010/05/10 21:40:22 1.548 +++ deliantra/server/lib/cf.pm 2010/07/03 01:49:18 1.556 @@ -385,6 +385,23 @@ push @POST_INIT, shift; } +sub _post_init { + trace "running post_init jobs"; + + # run them in parallel... + + my @join; + + while () { + push @join, map &Coro::async ($_, 0), @POST_INIT; + @POST_INIT = (); + + @join or last; + + (pop @join)->join; + } +} + =item cf::lock_wait $string Wait until the given lock is available. See cf::lock_acquire. @@ -1664,13 +1681,13 @@ $pl->{deny_save} = 1; $pl->password ("*"); # this should lock out the player until we have nuked the dir - $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1) if $pl->active; + $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1) if $pl->ns; $pl->deactivate; my $killer = cf::arch::get "killer_quit"; $pl->killer ($killer); $killer->destroy; + $pl->invoke (cf::EVENT_PLAYER_QUIT) if $pl->ns; ext::highscore::check ($pl->ob); - $pl->invoke (cf::EVENT_PLAYER_QUIT); $pl->ns->destroy if $pl->ns; my $path = playerdir $pl; @@ -1846,20 +1863,7 @@ my $lock = cf::lock_acquire "generate_random_map"; # the random map generator is NOT reentrant ATM - # mit "rum" bekleckern, nicht - $self->_create_random_map ( - $rmp->{wallstyle}, $rmp->{wall_name}, $rmp->{floorstyle}, $rmp->{monsterstyle}, - $rmp->{treasurestyle}, $rmp->{layoutstyle}, $rmp->{doorstyle}, $rmp->{decorstyle}, $rmp->{miningstyle}, - $rmp->{origin_map}, $rmp->{final_map}, $rmp->{exitstyle}, $rmp->{this_map}, - $rmp->{exit_on_final_map}, - $rmp->{xsize}, $rmp->{ysize}, - $rmp->{expand2x}, $rmp->{layoutoptions1}, $rmp->{layoutoptions2}, $rmp->{layoutoptions3}, - $rmp->{symmetry}, $rmp->{difficulty}, $rmp->{difficulty_given}, $rmp->{difficulty_increase}, - $rmp->{dungeon_level}, $rmp->{dungeon_depth}, $rmp->{decoroptions}, $rmp->{orientation}, - $rmp->{origin_y}, $rmp->{origin_x}, $rmp->{random_seed}, $rmp->{total_map_hp}, - $rmp->{map_layout_style}, $rmp->{treasureoptions}, $rmp->{symmetry_used}, - (cf::region::find $rmp->{region}), $rmp->{custom} - ) + $self->_create_random_map ($rmp); } =item cf::map->register ($regex, $prio) @@ -1920,7 +1924,6 @@ } for ($path) { - redo if s{//}{/}; redo if s{/\.?/}{/}; redo if s{/[^/]+/\.\./}{/}; } @@ -2172,6 +2175,8 @@ } $self->post_load; + + 1 } # customize the map for a given player, i.e. @@ -3662,7 +3667,7 @@ use POSIX (); POSIX::close delete $ENV{LOCKUTIL_LOCK_FD} if exists $ENV{LOCKUTIL_LOCK_FD}; - (pop @POST_INIT)->(0) while @POST_INIT; + cf::_post_init 0; }; cf::object::thawer::errors_are_fatal 0; @@ -3895,25 +3900,25 @@ while ($RELOAD) { cf::get_slot 0.1, -1, "reload_perl"; - info "reloading..."; + info "perl_reload: reloading..."; - trace "entering sync_job"; + trace "perl_reload: entering sync_job"; cf::sync_job { #cf::emergency_save; - trace "cancelling all extension coros"; + trace "perl_reload: cancelling all extension coros"; $_->cancel for values %EXT_CORO; %EXT_CORO = (); - trace "removing commands"; + trace "perl_reload: removing commands"; %COMMAND = (); - trace "removing ext/exti commands"; + trace "perl_reload: removing ext/exti commands"; %EXTCMD = (); %EXTICMD = (); - trace "unloading/nuking all extensions"; + trace "perl_reload: unloading/nuking all extensions"; for my $pkg (@EXTS) { trace "... unloading $pkg"; @@ -3928,7 +3933,7 @@ clear_package $pkg; } - trace "unloading all perl modules loaded from $LIBDIR"; + trace "perl_reload: unloading all perl modules loaded from $LIBDIR"; while (my ($k, $v) = each %INC) { next unless $v =~ /^\Q$LIBDIR\E\/.*\.pm$/; @@ -3945,11 +3950,11 @@ clear_package $k; } - trace "getting rid of safe::, as good as possible"; + trace "perl_reload: getting rid of safe::, as good as possible"; clear_package "safe::$_" for qw(cf::attachable cf::object cf::object::player cf::client cf::player cf::map cf::party cf::region); - trace "unloading cf.pm \"a bit\""; + trace "perl_reload: unloading cf.pm \"a bit\""; delete $INC{"cf.pm"}; delete $INC{"cf/$_.pm"} for @EXTRA_MODULES; @@ -3957,44 +3962,42 @@ # and global variables created in xs #clear_package __PACKAGE__; - info "unload completed, starting to reload now"; + info "perl_reload: unload completed, starting to reload now"; - trace "reloading cf.pm"; + trace "perl_reload: reloading cf.pm"; require cf; cf::_connect_to_perl_1; - trace "loading config and database again"; + trace "perl_reload: loading config and database again"; cf::reload_config; - trace "loading extensions"; + trace "perl_reload: loading extensions"; cf::load_extensions; if ($REATTACH_ON_RELOAD) { - trace "reattaching attachments to objects/players"; + trace "perl_reload: reattaching attachments to objects/players"; _global_reattach; # objects, sockets - trace "reattaching attachments to maps"; + trace "perl_reload: reattaching attachments to maps"; reattach $_ for values %MAP; - trace "reattaching attachments to players"; + trace "perl_reload: reattaching attachments to players"; reattach $_ for values %PLAYER; } - trace "running post_init jobs"; - (pop @POST_INIT)->(1) while @POST_INIT; + cf::_post_init 1; - trace "leaving sync_job"; + trace "perl_reload: leaving sync_job"; 1 } or do { error $@; - cf::cleanup "error while reloading, exiting."; + cf::cleanup "perl_reload: error, exiting."; }; - info "reloaded"; --$RELOAD; } $t1 = AE::time - $t1; - info "reload completed in ${t1}s\n"; + info "perl_reload: completed in ${t1}s\n"; }; our $RELOAD_WATCHER; # used only during reload @@ -4137,15 +4140,20 @@ undef $AnyEvent::AIO::WATCHER; } -my $_log_backtrace; +our $_log_backtrace; +our $_log_backtrace_last; sub _log_backtrace { my ($msg, @addr) = @_; - $msg =~ s/\n//; + $msg =~ s/\n$//; + if ($_log_backtrace_last eq $msg) { + LOG llevInfo, "[ABT] $msg\n"; + LOG llevInfo, "[ABT] [duplicate, suppressed]\n"; # limit the # of concurrent backtraces - if ($_log_backtrace < 2) { + } elsif ($_log_backtrace < 2) { + $_log_backtrace_last = $msg; ++$_log_backtrace; my $perl_bt = Carp::longmess $msg; async { @@ -4175,7 +4183,7 @@ }; } else { LOG llevInfo, "[ABT] $msg\n"; - LOG llevInfo, "[ABT] [suppressed]\n"; + LOG llevInfo, "[ABT] [overload, suppressed]\n"; } }