--- deliantra/server/lib/cf.pm 2010/05/11 13:19:59 1.549 +++ deliantra/server/lib/cf.pm 2010/05/14 22:56:47 1.550 @@ -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. @@ -3662,7 +3679,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 +3912,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 +3945,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 +3962,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 +3974,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