ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/lib/cf.pm
(Generate patch)

Comparing deliantra/server/lib/cf.pm (file contents):
Revision 1.541 by root, Tue May 4 23:33:16 2010 UTC vs.
Revision 1.556 by root, Sat Jul 3 01:49:18 2010 UTC

124our $BDB_DEADLOCK_WATCHER; 124our $BDB_DEADLOCK_WATCHER;
125our $BDB_CHECKPOINT_WATCHER; 125our $BDB_CHECKPOINT_WATCHER;
126our $BDB_TRICKLE_WATCHER; 126our $BDB_TRICKLE_WATCHER;
127our $DB_ENV; 127our $DB_ENV;
128 128
129our @EXTRA_MODULES = qw(pod match mapscript); 129our @EXTRA_MODULES = qw(pod match mapscript incloader);
130 130
131our %CFG; 131our %CFG;
132 132
133our $UPTIME; $UPTIME ||= time; 133our $UPTIME; $UPTIME ||= time;
134our $RUNTIME; 134our $RUNTIME;
233from wherever your confdir points to. 233from wherever your confdir points to.
234 234
235=item cf::wait_for_tick, cf::wait_for_tick_begin 235=item cf::wait_for_tick, cf::wait_for_tick_begin
236 236
237These are functions that inhibit the current coroutine one tick. cf::wait_for_tick_begin only 237These are functions that inhibit the current coroutine one tick. cf::wait_for_tick_begin only
238returns directly I<after> the tick processing (and consequently, can only wake one process 238returns directly I<after> the tick processing (and consequently, can only wake one thread
239per tick), while cf::wait_for_tick wakes up all waiters after tick processing. 239per tick), while cf::wait_for_tick wakes up all waiters after tick processing.
240
241=cut
242
243sub wait_for_tick();
244sub wait_for_tick_begin();
240 245
241=item @cf::INVOKE_RESULTS 246=item @cf::INVOKE_RESULTS
242 247
243This array contains the results of the last C<invoke ()> call. When 248This array contains the results of the last C<invoke ()> call. When
244C<cf::override> is called C<@cf::INVOKE_RESULTS> is set to the parameters of 249C<cf::override> is called C<@cf::INVOKE_RESULTS> is set to the parameters of
352our $json_coder = JSON::XS->new->utf8->max_size (1e6); # accept ~1mb max 357our $json_coder = JSON::XS->new->utf8->max_size (1e6); # accept ~1mb max
353 358
354sub encode_json($) { $json_coder->encode ($_[0]) } 359sub encode_json($) { $json_coder->encode ($_[0]) }
355sub decode_json($) { $json_coder->decode ($_[0]) } 360sub decode_json($) { $json_coder->decode ($_[0]) }
356 361
362=item $ref = cf::yaml_load $scalar
363
364Same as YAML::XS::Load, but doesn't leak, because it forks (and thus blocks).
365
366=cut
367
368sub fork_call(&@);
369
370sub yaml_load($) {
371 fork_call { YAML::XS::Load $_[0] } @_
372}
373
357=item cf::post_init { BLOCK } 374=item cf::post_init { BLOCK }
358 375
359Execute the given codeblock, I<after> all extensions have been (re-)loaded, 376Execute the given codeblock, I<after> all extensions have been (re-)loaded,
360but I<before> the server starts ticking again. 377but I<before> the server starts ticking again.
361 378
362The cdoeblock will have a single boolean argument to indicate whether this 379The codeblock will have a single boolean argument to indicate whether this
363is a reload or not. 380is a reload or not.
364 381
365=cut 382=cut
366 383
367sub post_init(&) { 384sub post_init(&) {
368 push @POST_INIT, shift; 385 push @POST_INIT, shift;
386}
387
388sub _post_init {
389 trace "running post_init jobs";
390
391 # run them in parallel...
392
393 my @join;
394
395 while () {
396 push @join, map &Coro::async ($_, 0), @POST_INIT;
397 @POST_INIT = ();
398
399 @join or last;
400
401 (pop @join)->join;
402 }
369} 403}
370 404
371=item cf::lock_wait $string 405=item cf::lock_wait $string
372 406
373Wait until the given lock is available. See cf::lock_acquire. 407Wait until the given lock is available. See cf::lock_acquire.
578 $EXT_CORO{$coro+0} = $coro; 612 $EXT_CORO{$coro+0} = $coro;
579 613
580 $coro 614 $coro
581} 615}
582 616
583=item fork_call { }, $args 617=item fork_call { }, @args
584 618
585Executes the given code block with the given arguments in a seperate 619Executes the given code block with the given arguments in a seperate
586process, returning the results. Everything must be serialisable with 620process, returning the results. Everything must be serialisable with
587Coro::Storable. May, of course, block. Note that the executed sub may 621Coro::Storable. May, of course, block. Note that the executed sub may
588never block itself or use any form of event handling. 622never block itself or use any form of event handling.
589 623
590=cut 624=cut
591 625
626sub post_fork {
627 reset_signals;
628}
629
592sub fork_call(&@) { 630sub fork_call(&@) {
593 my ($cb, @args) = @_; 631 my ($cb, @args) = @_;
594 632
595 # we seemingly have to make a local copy of the whole thing, 633 # we seemingly have to make a local copy of the whole thing,
596 # otherwise perl prematurely frees the stuff :/ 634 # otherwise perl prematurely frees the stuff :/
597 # TODO: investigate and fix (likely this will be rather laborious) 635 # TODO: investigate and fix (likely this will be rather laborious)
598 636
599 my @res = Coro::Util::fork_eval { 637 my @res = Coro::Util::fork_eval {
600 reset_signals; 638 cf::post_fork;
601 &$cb 639 &$cb
602 }, @args; 640 } @args;
603 641
604 wantarray ? @res : $res[-1] 642 wantarray ? @res : $res[-1]
605} 643}
606 644
607sub objinfo { 645sub objinfo {
1451 1489
1452 my $active = eval $v->{source}; 1490 my $active = eval $v->{source};
1453 1491
1454 if (length $@) { 1492 if (length $@) {
1455 error "$v->{path}: $@\n"; 1493 error "$v->{path}: $@\n";
1456 undef $@; # work around perl 5.10.0 utf-8 caching bug
1457 1494
1458 cf::cleanup "mandatory extension '$k' failed to load, exiting." 1495 cf::cleanup "mandatory extension '$k' failed to load, exiting."
1459 if exists $v->{meta}{mandatory}; 1496 if exists $v->{meta}{mandatory};
1460 1497
1461 warn "$v->{base}: optional extension cannot be loaded, skipping.\n"; 1498 warn "$v->{base}: optional extension cannot be loaded, skipping.\n";
1642 my $name = $pl->ob->name; 1679 my $name = $pl->ob->name;
1643 1680
1644 $pl->{deny_save} = 1; 1681 $pl->{deny_save} = 1;
1645 $pl->password ("*"); # this should lock out the player until we have nuked the dir 1682 $pl->password ("*"); # this should lock out the player until we have nuked the dir
1646 1683
1647 $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1) if $pl->active; 1684 $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1) if $pl->ns;
1648 $pl->deactivate; 1685 $pl->deactivate;
1686
1649 my $killer = cf::arch::get "killer_quit"; $pl->killer ($killer); $killer->destroy; 1687 my $killer = cf::arch::get "killer_quit"; $pl->killer ($killer); $killer->destroy;
1650 $pl->invoke (cf::EVENT_PLAYER_QUIT); 1688 $pl->invoke (cf::EVENT_PLAYER_QUIT) if $pl->ns;
1689 ext::highscore::check ($pl->ob);
1690
1651 $pl->ns->destroy if $pl->ns; 1691 $pl->ns->destroy if $pl->ns;
1652 1692
1653 my $path = playerdir $pl; 1693 my $path = playerdir $pl;
1654 my $temp = "$path~$cf::RUNTIME~deleting~"; 1694 my $temp = "$path~$cf::RUNTIME~deleting~";
1655 aio_rename $path, $temp; 1695 aio_rename $path, $temp;
1821sub generate_random_map { 1861sub generate_random_map {
1822 my ($self, $rmp) = @_; 1862 my ($self, $rmp) = @_;
1823 1863
1824 my $lock = cf::lock_acquire "generate_random_map"; # the random map generator is NOT reentrant ATM 1864 my $lock = cf::lock_acquire "generate_random_map"; # the random map generator is NOT reentrant ATM
1825 1865
1826 # mit "rum" bekleckern, nicht
1827 $self->_create_random_map ( 1866 $self->_create_random_map ($rmp);
1828 $rmp->{wallstyle}, $rmp->{wall_name}, $rmp->{floorstyle}, $rmp->{monsterstyle},
1829 $rmp->{treasurestyle}, $rmp->{layoutstyle}, $rmp->{doorstyle}, $rmp->{decorstyle}, $rmp->{miningstyle},
1830 $rmp->{origin_map}, $rmp->{final_map}, $rmp->{exitstyle}, $rmp->{this_map},
1831 $rmp->{exit_on_final_map},
1832 $rmp->{xsize}, $rmp->{ysize},
1833 $rmp->{expand2x}, $rmp->{layoutoptions1}, $rmp->{layoutoptions2}, $rmp->{layoutoptions3},
1834 $rmp->{symmetry}, $rmp->{difficulty}, $rmp->{difficulty_given}, $rmp->{difficulty_increase},
1835 $rmp->{dungeon_level}, $rmp->{dungeon_depth}, $rmp->{decoroptions}, $rmp->{orientation},
1836 $rmp->{origin_y}, $rmp->{origin_x}, $rmp->{random_seed}, $rmp->{total_map_hp},
1837 $rmp->{map_layout_style}, $rmp->{treasureoptions}, $rmp->{symmetry_used},
1838 (cf::region::find $rmp->{region}), $rmp->{custom}
1839 )
1840} 1867}
1841 1868
1842=item cf::map->register ($regex, $prio) 1869=item cf::map->register ($regex, $prio)
1843 1870
1844Register a handler for the map path matching the given regex at the 1871Register a handler for the map path matching the given regex at the
1870} 1897}
1871 1898
1872sub normalise { 1899sub normalise {
1873 my ($path, $base) = @_; 1900 my ($path, $base) = @_;
1874 1901
1875 $path = "$path"; # make sure its a string 1902 $path = "$path"; # make sure it's a string
1876 1903
1877 $path =~ s/\.map$//; 1904 $path =~ s/\.map$//;
1878 1905
1879 # map plan: 1906 # map plan:
1880 # 1907 #
1895 $base =~ s{[^/]+/?$}{}; 1922 $base =~ s{[^/]+/?$}{};
1896 $path = "$base/$path"; 1923 $path = "$base/$path";
1897 } 1924 }
1898 1925
1899 for ($path) { 1926 for ($path) {
1900 redo if s{//}{/};
1901 redo if s{/\.?/}{/}; 1927 redo if s{/\.?/}{/};
1902 redo if s{/[^/]+/\.\./}{/}; 1928 redo if s{/[^/]+/\.\./}{/};
1903 } 1929 }
1904 1930
1905 $path 1931 $path
1919 $self->init; # pass $1 etc. 1945 $self->init; # pass $1 etc.
1920 return $self; 1946 return $self;
1921 } 1947 }
1922 } 1948 }
1923 1949
1924 Carp::cluck "unable to resolve path '$path' (base '$base')."; 1950 Carp::cluck "unable to resolve path '$path' (base '$base')";
1925 () 1951 ()
1926} 1952}
1927 1953
1928sub init { 1954sub init {
1929 my ($self) = @_; 1955 my ($self) = @_;
2051} 2077}
2052 2078
2053sub find; 2079sub find;
2054sub find { 2080sub find {
2055 my ($path, $origin) = @_; 2081 my ($path, $origin) = @_;
2082
2083 cf::cede_to_tick;
2056 2084
2057 $path = normalise $path, $origin && $origin->path; 2085 $path = normalise $path, $origin && $origin->path;
2058 2086
2059 my $guard1 = cf::lock_acquire "map_data:$path";#d#remove 2087 my $guard1 = cf::lock_acquire "map_data:$path";#d#remove
2060 my $guard2 = cf::lock_acquire "map_find:$path"; 2088 my $guard2 = cf::lock_acquire "map_find:$path";
2145 2173
2146 $self->in_memory (cf::MAP_ACTIVE); 2174 $self->in_memory (cf::MAP_ACTIVE);
2147 } 2175 }
2148 2176
2149 $self->post_load; 2177 $self->post_load;
2178
2179 1
2150} 2180}
2151 2181
2152# customize the map for a given player, i.e. 2182# customize the map for a given player, i.e.
2153# return the _real_ map. used by e.g. per-player 2183# return the _real_ map. used by e.g. per-player
2154# maps to change the path to ~playername/mappath 2184# maps to change the path to ~playername/mappath
3358=cut 3388=cut
3359 3389
3360############################################################################# 3390#############################################################################
3361# the server's init and main functions 3391# the server's init and main functions
3362 3392
3363# async inc loader. yay.
3364sub inc_loader {
3365 my $mod = $_[1];
3366
3367 if (in_main && !tick_inhibit) {
3368 Carp::cluck "ERROR: attempted synchronous perl module load ($mod)";
3369 } else {
3370 debug "loading perl module $mod\n";
3371 }
3372
3373 # 1. find real file
3374 for my $dir (@ORIG_INC) {
3375 ref $dir and next;
3376 0 <= Coro::AIO::aio_load "$dir/$mod", my $data
3377 or next;
3378
3379 $data = "#line 1 $dir/$mod\n$data";
3380
3381 open my $fh, "<", \$data or die;
3382
3383 return $fh;
3384 }
3385
3386 ()
3387}
3388
3389sub init_inc {
3390 # save original @INC
3391 @ORIG_INC = ($LIBDIR, @INC) unless @ORIG_INC;
3392
3393 # make sure we can do scalar-opens
3394 open my $dummy, "<", \my $dummy2;
3395
3396 # execute some stuff so perl load's some of the core modules
3397 /Ü/ =~ /ü/i;
3398 eval { &Storable::nstore_fd };
3399
3400 @INC = (\&inc_loader, @ORIG_INC); # @ORIG_INC is needed for DynaLoader, AutoLoad etc.
3401
3402 debug "module loading will be asynchronous from this point on.";
3403}
3404
3405sub load_facedata($) { 3393sub load_facedata($) {
3406 my ($path) = @_; 3394 my ($path) = @_;
3407 3395
3408 # HACK to clear player env face cache, we need some signal framework 3396 # HACK to clear player env face cache, we need some signal framework
3409 # for this (global event?) 3397 # for this (global event?)
3411 3399
3412 my $enc = JSON::XS->new->utf8->canonical->relaxed; 3400 my $enc = JSON::XS->new->utf8->canonical->relaxed;
3413 3401
3414 trace "loading facedata from $path\n"; 3402 trace "loading facedata from $path\n";
3415 3403
3416 my $facedata;
3417 0 < aio_load $path, $facedata 3404 0 < aio_load $path, my $facedata
3418 or die "$path: $!"; 3405 or die "$path: $!";
3419 3406
3420 $facedata = Coro::Storable::thaw $facedata; 3407 $facedata = Coro::Storable::thaw $facedata;
3421 3408
3422 $facedata->{version} == 2 3409 $facedata->{version} == 2
3566} 3553}
3567 3554
3568sub reload_resources { 3555sub reload_resources {
3569 trace "reloading resource files...\n"; 3556 trace "reloading resource files...\n";
3570 3557
3558 reload_exp_table;
3559 reload_materials;
3571 reload_facedata; 3560 reload_facedata;
3572 reload_sound; 3561 reload_sound;
3573 reload_archetypes; 3562 reload_archetypes;
3574 reload_regions; 3563 reload_regions;
3575 reload_treasures; 3564 reload_treasures;
3578} 3567}
3579 3568
3580sub reload_config { 3569sub reload_config {
3581 trace "reloading config file...\n"; 3570 trace "reloading config file...\n";
3582 3571
3583 open my $fh, "<:utf8", "$CONFDIR/config" 3572 0 < aio_load "$CONFDIR/config", my $config
3584 or return; 3573 or die "$CONFDIR/config: $!";
3585 3574
3586 local $/; 3575 utf8::decode $config;
3587 *CFG = YAML::XS::Load scalar <$fh>; 3576 *CFG = yaml_load $config;
3588 3577
3589 $EMERGENCY_POSITION = $CFG{emergency_position} || ["/world/world_104_115", 49, 38]; 3578 $EMERGENCY_POSITION = $CFG{emergency_position} || ["/world/world_104_115", 49, 38];
3590 3579
3591 $cf::map::MAX_RESET = $CFG{map_max_reset} if exists $CFG{map_max_reset}; 3580 $cf::map::MAX_RESET = $CFG{map_max_reset} if exists $CFG{map_max_reset};
3592 $cf::map::DEFAULT_RESET = $CFG{map_default_reset} if exists $CFG{map_default_reset}; 3581 $cf::map::DEFAULT_RESET = $CFG{map_default_reset} if exists $CFG{map_default_reset};
3596 $CFG{mlockall} ? eval "mlockall()" : eval "munlockall()" 3585 $CFG{mlockall} ? eval "mlockall()" : eval "munlockall()"
3597 and die "WARNING: m(un)lockall failed: $!\n"; 3586 and die "WARNING: m(un)lockall failed: $!\n";
3598 }; 3587 };
3599 warn $@ if $@; 3588 warn $@ if $@;
3600 } 3589 }
3601
3602 trace "finished reloading resource files\n";
3603} 3590}
3604 3591
3605sub pidfile() { 3592sub pidfile() {
3606 sysopen my $fh, $PIDFILE, O_RDWR | O_CREAT 3593 sysopen my $fh, $PIDFILE, O_RDWR | O_CREAT
3607 or die "$PIDFILE: $!"; 3594 or die "$PIDFILE: $!";
3650 }; 3637 };
3651 3638
3652 evthread_start IO::AIO::poll_fileno; 3639 evthread_start IO::AIO::poll_fileno;
3653 3640
3654 cf::sync_job { 3641 cf::sync_job {
3655 init_inc; 3642 cf::incloader::init ();
3656 3643
3657 cf::init_experience;
3658 cf::init_anim; 3644 cf::init_anim;
3659 cf::init_attackmess; 3645 cf::init_attackmess;
3660 cf::init_dynamic; 3646 cf::init_dynamic;
3661 3647
3662 cf::load_settings; 3648 cf::load_settings;
3663 cf::load_materials;
3664 3649
3665 reload_resources; 3650 reload_resources;
3666 reload_config; 3651 reload_config;
3667 db_init; 3652 db_init;
3668 3653
3680 3665
3681 # no (long-running) fork's whatsoever before this point(!) 3666 # no (long-running) fork's whatsoever before this point(!)
3682 use POSIX (); 3667 use POSIX ();
3683 POSIX::close delete $ENV{LOCKUTIL_LOCK_FD} if exists $ENV{LOCKUTIL_LOCK_FD}; 3668 POSIX::close delete $ENV{LOCKUTIL_LOCK_FD} if exists $ENV{LOCKUTIL_LOCK_FD};
3684 3669
3685 (pop @POST_INIT)->(0) while @POST_INIT; 3670 cf::_post_init 0;
3686 }; 3671 };
3687 3672
3688 cf::object::thawer::errors_are_fatal 0; 3673 cf::object::thawer::errors_are_fatal 0;
3689 info "parse errors in files are no longer fatal from this point on.\n"; 3674 info "parse errors in files are no longer fatal from this point on.\n";
3690 3675
3902 } 3887 }
3903} 3888}
3904 3889
3905sub do_reload_perl() { 3890sub do_reload_perl() {
3906 # can/must only be called in main 3891 # can/must only be called in main
3907 if (in_main) { 3892 unless (in_main) {
3908 error "can only reload from main coroutine"; 3893 error "can only reload from main coroutine";
3909 return; 3894 return;
3910 } 3895 }
3911 3896
3912 return if $RELOAD++; 3897 return if $RELOAD++;
3913 3898
3914 my $t1 = AE::time; 3899 my $t1 = AE::time;
3915 3900
3916 while ($RELOAD) { 3901 while ($RELOAD) {
3902 cf::get_slot 0.1, -1, "reload_perl";
3917 info "reloading..."; 3903 info "perl_reload: reloading...";
3918 3904
3919 trace "entering sync_job"; 3905 trace "perl_reload: entering sync_job";
3920 3906
3921 cf::sync_job { 3907 cf::sync_job {
3922 cf::emergency_save; 3908 #cf::emergency_save;
3923 3909
3924 trace "cancelling all extension coros"; 3910 trace "perl_reload: cancelling all extension coros";
3925 $_->cancel for values %EXT_CORO; 3911 $_->cancel for values %EXT_CORO;
3926 %EXT_CORO = (); 3912 %EXT_CORO = ();
3927 3913
3928 trace "removing commands"; 3914 trace "perl_reload: removing commands";
3929 %COMMAND = (); 3915 %COMMAND = ();
3930 3916
3931 trace "removing ext/exti commands"; 3917 trace "perl_reload: removing ext/exti commands";
3932 %EXTCMD = (); 3918 %EXTCMD = ();
3933 %EXTICMD = (); 3919 %EXTICMD = ();
3934 3920
3935 trace "unloading/nuking all extensions"; 3921 trace "perl_reload: unloading/nuking all extensions";
3936 for my $pkg (@EXTS) { 3922 for my $pkg (@EXTS) {
3937 trace "... unloading $pkg"; 3923 trace "... unloading $pkg";
3938 3924
3939 if (my $cb = $pkg->can ("unload")) { 3925 if (my $cb = $pkg->can ("unload")) {
3940 eval { 3926 eval {
3945 3931
3946 trace "... clearing $pkg"; 3932 trace "... clearing $pkg";
3947 clear_package $pkg; 3933 clear_package $pkg;
3948 } 3934 }
3949 3935
3950 trace "unloading all perl modules loaded from $LIBDIR"; 3936 trace "perl_reload: unloading all perl modules loaded from $LIBDIR";
3951 while (my ($k, $v) = each %INC) { 3937 while (my ($k, $v) = each %INC) {
3952 next unless $v =~ /^\Q$LIBDIR\E\/.*\.pm$/; 3938 next unless $v =~ /^\Q$LIBDIR\E\/.*\.pm$/;
3953 3939
3954 trace "... unloading $k"; 3940 trace "... unloading $k";
3955 delete $INC{$k}; 3941 delete $INC{$k};
3962 } 3948 }
3963 3949
3964 clear_package $k; 3950 clear_package $k;
3965 } 3951 }
3966 3952
3967 trace "getting rid of safe::, as good as possible"; 3953 trace "perl_reload: getting rid of safe::, as good as possible";
3968 clear_package "safe::$_" 3954 clear_package "safe::$_"
3969 for qw(cf::attachable cf::object cf::object::player cf::client cf::player cf::map cf::party cf::region); 3955 for qw(cf::attachable cf::object cf::object::player cf::client cf::player cf::map cf::party cf::region);
3970 3956
3971 trace "unloading cf.pm \"a bit\""; 3957 trace "perl_reload: unloading cf.pm \"a bit\"";
3972 delete $INC{"cf.pm"}; 3958 delete $INC{"cf.pm"};
3973 delete $INC{"cf/$_.pm"} for @EXTRA_MODULES; 3959 delete $INC{"cf/$_.pm"} for @EXTRA_MODULES;
3974 3960
3975 # don't, removes xs symbols, too, 3961 # don't, removes xs symbols, too,
3976 # and global variables created in xs 3962 # and global variables created in xs
3977 #clear_package __PACKAGE__; 3963 #clear_package __PACKAGE__;
3978 3964
3979 info "unload completed, starting to reload now"; 3965 info "perl_reload: unload completed, starting to reload now";
3980 3966
3981 trace "reloading cf.pm"; 3967 trace "perl_reload: reloading cf.pm";
3982 require cf; 3968 require cf;
3983 cf::_connect_to_perl_1; 3969 cf::_connect_to_perl_1;
3984 3970
3985 trace "loading config and database again"; 3971 trace "perl_reload: loading config and database again";
3986 cf::reload_config; 3972 cf::reload_config;
3987 3973
3988 trace "loading extensions"; 3974 trace "perl_reload: loading extensions";
3989 cf::load_extensions; 3975 cf::load_extensions;
3990 3976
3991 if ($REATTACH_ON_RELOAD) { 3977 if ($REATTACH_ON_RELOAD) {
3992 trace "reattaching attachments to objects/players"; 3978 trace "perl_reload: reattaching attachments to objects/players";
3993 _global_reattach; # objects, sockets 3979 _global_reattach; # objects, sockets
3994 trace "reattaching attachments to maps"; 3980 trace "perl_reload: reattaching attachments to maps";
3995 reattach $_ for values %MAP; 3981 reattach $_ for values %MAP;
3996 trace "reattaching attachments to players"; 3982 trace "perl_reload: reattaching attachments to players";
3997 reattach $_ for values %PLAYER; 3983 reattach $_ for values %PLAYER;
3998 } 3984 }
3999 3985
4000 trace "running post_init jobs"; 3986 cf::_post_init 1;
4001 (pop @POST_INIT)->(1) while @POST_INIT;
4002 3987
4003 trace "leaving sync_job"; 3988 trace "perl_reload: leaving sync_job";
4004 3989
4005 1 3990 1
4006 } or do { 3991 } or do {
4007 error $@; 3992 error $@;
4008 cf::cleanup "error while reloading, exiting."; 3993 cf::cleanup "perl_reload: error, exiting.";
4009 }; 3994 };
4010 3995
4011 info "reloaded";
4012 --$RELOAD; 3996 --$RELOAD;
4013 } 3997 }
4014 3998
4015 $t1 = AE::time - $t1; 3999 $t1 = AE::time - $t1;
4016 info "reload completed in ${t1}s\n"; 4000 info "perl_reload: completed in ${t1}s\n";
4017}; 4001};
4018 4002
4019our $RELOAD_WATCHER; # used only during reload 4003our $RELOAD_WATCHER; # used only during reload
4020 4004
4021sub reload_perl() { 4005sub reload_perl() {
4049my $bug_warning = 0; 4033my $bug_warning = 0;
4050 4034
4051our @WAIT_FOR_TICK; 4035our @WAIT_FOR_TICK;
4052our @WAIT_FOR_TICK_BEGIN; 4036our @WAIT_FOR_TICK_BEGIN;
4053 4037
4054sub wait_for_tick { 4038sub wait_for_tick() {
4055 return Coro::cede if tick_inhibit || $Coro::current == $Coro::main; 4039 return Coro::cede if tick_inhibit || $Coro::current == $Coro::main;
4056 4040
4057 my $signal = new Coro::Signal; 4041 my $signal = new Coro::Signal;
4058 push @WAIT_FOR_TICK, $signal; 4042 push @WAIT_FOR_TICK, $signal;
4059 $signal->wait; 4043 $signal->wait;
4060} 4044}
4061 4045
4062sub wait_for_tick_begin { 4046sub wait_for_tick_begin() {
4063 return Coro::cede if tick_inhibit || $Coro::current == $Coro::main; 4047 return Coro::cede if tick_inhibit || $Coro::current == $Coro::main;
4064 4048
4065 my $signal = new Coro::Signal; 4049 my $signal = new Coro::Signal;
4066 push @WAIT_FOR_TICK_BEGIN, $signal; 4050 push @WAIT_FOR_TICK_BEGIN, $signal;
4067 $signal->wait; 4051 $signal->wait;
4154 IO::AIO::min_parallel 8; 4138 IO::AIO::min_parallel 8;
4155 IO::AIO::max_poll_time $TICK * 0.1; 4139 IO::AIO::max_poll_time $TICK * 0.1;
4156 undef $AnyEvent::AIO::WATCHER; 4140 undef $AnyEvent::AIO::WATCHER;
4157} 4141}
4158 4142
4159my $_log_backtrace; 4143our $_log_backtrace;
4144our $_log_backtrace_last;
4160 4145
4161sub _log_backtrace { 4146sub _log_backtrace {
4162 my ($msg, @addr) = @_; 4147 my ($msg, @addr) = @_;
4163 4148
4164 $msg =~ s/\n//; 4149 $msg =~ s/\n$//;
4165 4150
4151 if ($_log_backtrace_last eq $msg) {
4152 LOG llevInfo, "[ABT] $msg\n";
4153 LOG llevInfo, "[ABT] [duplicate, suppressed]\n";
4166 # limit the # of concurrent backtraces 4154 # limit the # of concurrent backtraces
4167 if ($_log_backtrace < 2) { 4155 } elsif ($_log_backtrace < 2) {
4156 $_log_backtrace_last = $msg;
4168 ++$_log_backtrace; 4157 ++$_log_backtrace;
4169 my $perl_bt = Carp::longmess $msg; 4158 my $perl_bt = Carp::longmess $msg;
4170 async { 4159 async {
4171 $Coro::current->{desc} = "abt $msg"; 4160 $Coro::current->{desc} = "abt $msg";
4172 4161
4192 LOG llevInfo, "[ABT] $_\n" for @bt; 4181 LOG llevInfo, "[ABT] $_\n" for @bt;
4193 --$_log_backtrace; 4182 --$_log_backtrace;
4194 }; 4183 };
4195 } else { 4184 } else {
4196 LOG llevInfo, "[ABT] $msg\n"; 4185 LOG llevInfo, "[ABT] $msg\n";
4197 LOG llevInfo, "[ABT] [suppressed]\n"; 4186 LOG llevInfo, "[ABT] [overload, suppressed]\n";
4198 } 4187 }
4199} 4188}
4200 4189
4201# load additional modules 4190# load additional modules
4202require "cf/$_.pm" for @EXTRA_MODULES; 4191require "cf/$_.pm" for @EXTRA_MODULES;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines