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.539 by root, Tue May 4 22:49:21 2010 UTC vs.
Revision 1.558 by root, Tue Oct 5 22:35:30 2010 UTC

76# strictly for debugging 76# strictly for debugging
77$SIG{QUIT} = sub { Carp::cluck "SIGQUIT" }; 77$SIG{QUIT} = sub { Carp::cluck "SIGQUIT" };
78 78
79sub WF_AUTOCANCEL () { 1 } # automatically cancel this watcher on reload 79sub WF_AUTOCANCEL () { 1 } # automatically cancel this watcher on reload
80 80
81our @ORIG_INC;
82
81our %COMMAND = (); 83our %COMMAND = ();
82our %COMMAND_TIME = (); 84our %COMMAND_TIME = ();
83 85
84our @EXTS = (); # list of extension package names 86our @EXTS = (); # list of extension package names
85our %EXTCMD = (); 87our %EXTCMD = ();
122our $BDB_DEADLOCK_WATCHER; 124our $BDB_DEADLOCK_WATCHER;
123our $BDB_CHECKPOINT_WATCHER; 125our $BDB_CHECKPOINT_WATCHER;
124our $BDB_TRICKLE_WATCHER; 126our $BDB_TRICKLE_WATCHER;
125our $DB_ENV; 127our $DB_ENV;
126 128
127our @EXTRA_MODULES = qw(pod match mapscript); 129our @EXTRA_MODULES = qw(pod match mapscript incloader);
128 130
129our %CFG; 131our %CFG;
130 132
131our $UPTIME; $UPTIME ||= time; 133our $UPTIME; $UPTIME ||= time;
132our $RUNTIME; 134our $RUNTIME;
231from wherever your confdir points to. 233from wherever your confdir points to.
232 234
233=item cf::wait_for_tick, cf::wait_for_tick_begin 235=item cf::wait_for_tick, cf::wait_for_tick_begin
234 236
235These 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
236returns 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
237per 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();
238 245
239=item @cf::INVOKE_RESULTS 246=item @cf::INVOKE_RESULTS
240 247
241This array contains the results of the last C<invoke ()> call. When 248This array contains the results of the last C<invoke ()> call. When
242C<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
350our $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
351 358
352sub encode_json($) { $json_coder->encode ($_[0]) } 359sub encode_json($) { $json_coder->encode ($_[0]) }
353sub decode_json($) { $json_coder->decode ($_[0]) } 360sub decode_json($) { $json_coder->decode ($_[0]) }
354 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
355=item cf::post_init { BLOCK } 374=item cf::post_init { BLOCK }
356 375
357Execute the given codeblock, I<after> all extensions have been (re-)loaded, 376Execute the given codeblock, I<after> all extensions have been (re-)loaded,
358but I<before> the server starts ticking again. 377but I<before> the server starts ticking again.
359 378
360The cdoeblock will have a single boolean argument to indicate whether this 379The codeblock will have a single boolean argument to indicate whether this
361is a reload or not. 380is a reload or not.
362 381
363=cut 382=cut
364 383
365sub post_init(&) { 384sub post_init(&) {
366 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 }
367} 403}
368 404
369=item cf::lock_wait $string 405=item cf::lock_wait $string
370 406
371Wait until the given lock is available. See cf::lock_acquire. 407Wait until the given lock is available. See cf::lock_acquire.
576 $EXT_CORO{$coro+0} = $coro; 612 $EXT_CORO{$coro+0} = $coro;
577 613
578 $coro 614 $coro
579} 615}
580 616
581=item fork_call { }, $args 617=item fork_call { }, @args
582 618
583Executes the given code block with the given arguments in a seperate 619Executes the given code block with the given arguments in a seperate
584process, returning the results. Everything must be serialisable with 620process, returning the results. Everything must be serialisable with
585Coro::Storable. May, of course, block. Note that the executed sub may 621Coro::Storable. May, of course, block. Note that the executed sub may
586never block itself or use any form of event handling. 622never block itself or use any form of event handling.
587 623
588=cut 624=cut
589 625
626sub post_fork {
627 reset_signals;
628}
629
590sub fork_call(&@) { 630sub fork_call(&@) {
591 my ($cb, @args) = @_; 631 my ($cb, @args) = @_;
592 632
593 # 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,
594 # otherwise perl prematurely frees the stuff :/ 634 # otherwise perl prematurely frees the stuff :/
595 # TODO: investigate and fix (likely this will be rather laborious) 635 # TODO: investigate and fix (likely this will be rather laborious)
596 636
597 my @res = Coro::Util::fork_eval { 637 my @res = Coro::Util::fork_eval {
598 reset_signals; 638 cf::post_fork;
599 &$cb 639 &$cb
600 }, @args; 640 } @args;
601 641
602 wantarray ? @res : $res[-1] 642 wantarray ? @res : $res[-1]
603} 643}
604 644
605sub objinfo { 645sub objinfo {
1449 1489
1450 my $active = eval $v->{source}; 1490 my $active = eval $v->{source};
1451 1491
1452 if (length $@) { 1492 if (length $@) {
1453 error "$v->{path}: $@\n"; 1493 error "$v->{path}: $@\n";
1454 undef $@; # work around perl 5.10.0 utf-8 caching bug
1455 1494
1456 cf::cleanup "mandatory extension '$k' failed to load, exiting." 1495 cf::cleanup "mandatory extension '$k' failed to load, exiting."
1457 if exists $v->{meta}{mandatory}; 1496 if exists $v->{meta}{mandatory};
1458 1497
1459 warn "$v->{base}: optional extension cannot be loaded, skipping.\n"; 1498 warn "$v->{base}: optional extension cannot be loaded, skipping.\n";
1640 my $name = $pl->ob->name; 1679 my $name = $pl->ob->name;
1641 1680
1642 $pl->{deny_save} = 1; 1681 $pl->{deny_save} = 1;
1643 $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
1644 1683
1645 $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1) if $pl->active; 1684 $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1) if $pl->ns;
1646 $pl->deactivate; 1685 $pl->deactivate;
1686
1647 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;
1648 $pl->invoke (cf::EVENT_PLAYER_QUIT); 1688 $pl->invoke (cf::EVENT_PLAYER_QUIT) if $pl->ns;
1689 ext::highscore::check ($pl->ob);
1690
1649 $pl->ns->destroy if $pl->ns; 1691 $pl->ns->destroy if $pl->ns;
1650 1692
1651 my $path = playerdir $pl; 1693 my $path = playerdir $pl;
1652 my $temp = "$path~$cf::RUNTIME~deleting~"; 1694 my $temp = "$path~$cf::RUNTIME~deleting~";
1653 aio_rename $path, $temp; 1695 aio_rename $path, $temp;
1819sub generate_random_map { 1861sub generate_random_map {
1820 my ($self, $rmp) = @_; 1862 my ($self, $rmp) = @_;
1821 1863
1822 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
1823 1865
1824 # mit "rum" bekleckern, nicht
1825 $self->_create_random_map ( 1866 $self->_create_random_map ($rmp);
1826 $rmp->{wallstyle}, $rmp->{wall_name}, $rmp->{floorstyle}, $rmp->{monsterstyle},
1827 $rmp->{treasurestyle}, $rmp->{layoutstyle}, $rmp->{doorstyle}, $rmp->{decorstyle}, $rmp->{miningstyle},
1828 $rmp->{origin_map}, $rmp->{final_map}, $rmp->{exitstyle}, $rmp->{this_map},
1829 $rmp->{exit_on_final_map},
1830 $rmp->{xsize}, $rmp->{ysize},
1831 $rmp->{expand2x}, $rmp->{layoutoptions1}, $rmp->{layoutoptions2}, $rmp->{layoutoptions3},
1832 $rmp->{symmetry}, $rmp->{difficulty}, $rmp->{difficulty_given}, $rmp->{difficulty_increase},
1833 $rmp->{dungeon_level}, $rmp->{dungeon_depth}, $rmp->{decoroptions}, $rmp->{orientation},
1834 $rmp->{origin_y}, $rmp->{origin_x}, $rmp->{random_seed}, $rmp->{total_map_hp},
1835 $rmp->{map_layout_style}, $rmp->{treasureoptions}, $rmp->{symmetry_used},
1836 (cf::region::find $rmp->{region}), $rmp->{custom}
1837 )
1838} 1867}
1839 1868
1840=item cf::map->register ($regex, $prio) 1869=item cf::map->register ($regex, $prio)
1841 1870
1842Register 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
1868} 1897}
1869 1898
1870sub normalise { 1899sub normalise {
1871 my ($path, $base) = @_; 1900 my ($path, $base) = @_;
1872 1901
1873 $path = "$path"; # make sure its a string 1902 $path = "$path"; # make sure it's a string
1874 1903
1875 $path =~ s/\.map$//; 1904 $path =~ s/\.map$//;
1876 1905
1877 # map plan: 1906 # map plan:
1878 # 1907 #
1893 $base =~ s{[^/]+/?$}{}; 1922 $base =~ s{[^/]+/?$}{};
1894 $path = "$base/$path"; 1923 $path = "$base/$path";
1895 } 1924 }
1896 1925
1897 for ($path) { 1926 for ($path) {
1898 redo if s{//}{/};
1899 redo if s{/\.?/}{/}; 1927 redo if s{/\.?/}{/};
1900 redo if s{/[^/]+/\.\./}{/}; 1928 redo if s{/[^/]+/\.\./}{/};
1901 } 1929 }
1902 1930
1903 $path 1931 $path
1917 $self->init; # pass $1 etc. 1945 $self->init; # pass $1 etc.
1918 return $self; 1946 return $self;
1919 } 1947 }
1920 } 1948 }
1921 1949
1922 Carp::cluck "unable to resolve path '$path' (base '$base')."; 1950 Carp::cluck "unable to resolve path '$path' (base '$base')";
1923 () 1951 ()
1924} 1952}
1925 1953
1926sub init { 1954sub init {
1927 my ($self) = @_; 1955 my ($self) = @_;
2049} 2077}
2050 2078
2051sub find; 2079sub find;
2052sub find { 2080sub find {
2053 my ($path, $origin) = @_; 2081 my ($path, $origin) = @_;
2082
2083 cf::cede_to_tick;
2054 2084
2055 $path = normalise $path, $origin && $origin->path; 2085 $path = normalise $path, $origin && $origin->path;
2056 2086
2057 my $guard1 = cf::lock_acquire "map_data:$path";#d#remove 2087 my $guard1 = cf::lock_acquire "map_data:$path";#d#remove
2058 my $guard2 = cf::lock_acquire "map_find:$path"; 2088 my $guard2 = cf::lock_acquire "map_find:$path";
2143 2173
2144 $self->in_memory (cf::MAP_ACTIVE); 2174 $self->in_memory (cf::MAP_ACTIVE);
2145 } 2175 }
2146 2176
2147 $self->post_load; 2177 $self->post_load;
2178
2179 1
2148} 2180}
2149 2181
2150# customize the map for a given player, i.e. 2182# customize the map for a given player, i.e.
2151# return the _real_ map. used by e.g. per-player 2183# return the _real_ map. used by e.g. per-player
2152# maps to change the path to ~playername/mappath 2184# maps to change the path to ~playername/mappath
3367 3399
3368 my $enc = JSON::XS->new->utf8->canonical->relaxed; 3400 my $enc = JSON::XS->new->utf8->canonical->relaxed;
3369 3401
3370 trace "loading facedata from $path\n"; 3402 trace "loading facedata from $path\n";
3371 3403
3372 my $facedata;
3373 0 < aio_load $path, $facedata 3404 0 < aio_load $path, my $facedata
3374 or die "$path: $!"; 3405 or die "$path: $!";
3375 3406
3376 $facedata = Coro::Storable::thaw $facedata; 3407 $facedata = Coro::Storable::thaw $facedata;
3377 3408
3378 $facedata->{version} == 2 3409 $facedata->{version} == 2
3395 3426
3396 cf::face::set_visibility $idx, $info->{visibility}; 3427 cf::face::set_visibility $idx, $info->{visibility};
3397 cf::face::set_magicmap $idx, $info->{magicmap}; 3428 cf::face::set_magicmap $idx, $info->{magicmap};
3398 cf::face::set_data $idx, 0, $info->{data32}, $info->{hash32}; 3429 cf::face::set_data $idx, 0, $info->{data32}, $info->{hash32};
3399 cf::face::set_data $idx, 1, $info->{data64}, $info->{hash64}; 3430 cf::face::set_data $idx, 1, $info->{data64}, $info->{hash64};
3431 cf::face::set_data $idx, 2, $info->{glyph} , $info->{glyph} ;
3400 3432
3401 cf::cede_to_tick; 3433 cf::cede_to_tick;
3402 } 3434 }
3403 3435
3404 while (my ($face, $info) = each %$faces) { 3436 while (my ($face, $info) = each %$faces) {
3522} 3554}
3523 3555
3524sub reload_resources { 3556sub reload_resources {
3525 trace "reloading resource files...\n"; 3557 trace "reloading resource files...\n";
3526 3558
3559 reload_exp_table;
3560 reload_materials;
3527 reload_facedata; 3561 reload_facedata;
3528 reload_sound; 3562 reload_sound;
3529 reload_archetypes; 3563 reload_archetypes;
3530 reload_regions; 3564 reload_regions;
3531 reload_treasures; 3565 reload_treasures;
3534} 3568}
3535 3569
3536sub reload_config { 3570sub reload_config {
3537 trace "reloading config file...\n"; 3571 trace "reloading config file...\n";
3538 3572
3539 open my $fh, "<:utf8", "$CONFDIR/config" 3573 0 < aio_load "$CONFDIR/config", my $config
3540 or return; 3574 or die "$CONFDIR/config: $!";
3541 3575
3542 local $/; 3576 utf8::decode $config;
3543 *CFG = YAML::XS::Load scalar <$fh>; 3577 *CFG = yaml_load $config;
3544 3578
3545 $EMERGENCY_POSITION = $CFG{emergency_position} || ["/world/world_104_115", 49, 38]; 3579 $EMERGENCY_POSITION = $CFG{emergency_position} || ["/world/world_104_115", 49, 38];
3546 3580
3547 $cf::map::MAX_RESET = $CFG{map_max_reset} if exists $CFG{map_max_reset}; 3581 $cf::map::MAX_RESET = $CFG{map_max_reset} if exists $CFG{map_max_reset};
3548 $cf::map::DEFAULT_RESET = $CFG{map_default_reset} if exists $CFG{map_default_reset}; 3582 $cf::map::DEFAULT_RESET = $CFG{map_default_reset} if exists $CFG{map_default_reset};
3552 $CFG{mlockall} ? eval "mlockall()" : eval "munlockall()" 3586 $CFG{mlockall} ? eval "mlockall()" : eval "munlockall()"
3553 and die "WARNING: m(un)lockall failed: $!\n"; 3587 and die "WARNING: m(un)lockall failed: $!\n";
3554 }; 3588 };
3555 warn $@ if $@; 3589 warn $@ if $@;
3556 } 3590 }
3557
3558 trace "finished reloading resource files\n";
3559} 3591}
3560 3592
3561sub pidfile() { 3593sub pidfile() {
3562 sysopen my $fh, $PIDFILE, O_RDWR | O_CREAT 3594 sysopen my $fh, $PIDFILE, O_RDWR | O_CREAT
3563 or die "$PIDFILE: $!"; 3595 or die "$PIDFILE: $!";
3588 3620
3589sub main { 3621sub main {
3590 cf::init_globals; # initialise logging 3622 cf::init_globals; # initialise logging
3591 3623
3592 LOG llevInfo, "Welcome to Deliantra, v" . VERSION; 3624 LOG llevInfo, "Welcome to Deliantra, v" . VERSION;
3593 LOG llevInfo, "Copyright (C) 2005-2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team."; 3625 LOG llevInfo, "Copyright (C) 2005-2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team.";
3594 LOG llevInfo, "Copyright (C) 1994 Mark Wedel."; 3626 LOG llevInfo, "Copyright (C) 1994 Mark Wedel.";
3595 LOG llevInfo, "Copyright (C) 1992 Frank Tore Johansen."; 3627 LOG llevInfo, "Copyright (C) 1992 Frank Tore Johansen.";
3596 3628
3597 $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority 3629 $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority
3598 3630
3606 }; 3638 };
3607 3639
3608 evthread_start IO::AIO::poll_fileno; 3640 evthread_start IO::AIO::poll_fileno;
3609 3641
3610 cf::sync_job { 3642 cf::sync_job {
3611 cf::init_experience; 3643 cf::incloader::init ();
3644
3612 cf::init_anim; 3645 cf::init_anim;
3613 cf::init_attackmess; 3646 cf::init_attackmess;
3614 cf::init_dynamic; 3647 cf::init_dynamic;
3615 3648
3616 cf::load_settings; 3649 cf::load_settings;
3617 cf::load_materials;
3618 3650
3619 reload_resources; 3651 reload_resources;
3620 reload_config; 3652 reload_config;
3621 db_init; 3653 db_init;
3622 3654
3634 3666
3635 # no (long-running) fork's whatsoever before this point(!) 3667 # no (long-running) fork's whatsoever before this point(!)
3636 use POSIX (); 3668 use POSIX ();
3637 POSIX::close delete $ENV{LOCKUTIL_LOCK_FD} if exists $ENV{LOCKUTIL_LOCK_FD}; 3669 POSIX::close delete $ENV{LOCKUTIL_LOCK_FD} if exists $ENV{LOCKUTIL_LOCK_FD};
3638 3670
3639 (pop @POST_INIT)->(0) while @POST_INIT; 3671 cf::_post_init 0;
3640 }; 3672 };
3641 3673
3642 cf::object::thawer::errors_are_fatal 0; 3674 cf::object::thawer::errors_are_fatal 0;
3643 info "parse errors in files are no longer fatal from this point on.\n"; 3675 info "parse errors in files are no longer fatal from this point on.\n";
3644 3676
3677 my $free_main; $free_main = EV::idle sub {
3678 undef $free_main;
3679 undef &main; # free gobs of memory :)
3680 };
3681
3645 main_loop; 3682 goto &main_loop;
3646} 3683}
3647 3684
3648############################################################################# 3685#############################################################################
3649# initialisation and cleanup 3686# initialisation and cleanup
3650 3687
3851 } 3888 }
3852} 3889}
3853 3890
3854sub do_reload_perl() { 3891sub do_reload_perl() {
3855 # can/must only be called in main 3892 # can/must only be called in main
3856 if (in_main) { 3893 unless (in_main) {
3857 error "can only reload from main coroutine"; 3894 error "can only reload from main coroutine";
3858 return; 3895 return;
3859 } 3896 }
3860 3897
3861 return if $RELOAD++; 3898 return if $RELOAD++;
3862 3899
3863 my $t1 = AE::time; 3900 my $t1 = AE::time;
3864 3901
3865 while ($RELOAD) { 3902 while ($RELOAD) {
3903 cf::get_slot 0.1, -1, "reload_perl";
3866 info "reloading..."; 3904 info "perl_reload: reloading...";
3867 3905
3868 trace "entering sync_job"; 3906 trace "perl_reload: entering sync_job";
3869 3907
3870 cf::sync_job { 3908 cf::sync_job {
3871 cf::emergency_save; 3909 #cf::emergency_save;
3872 3910
3873 trace "cancelling all extension coros"; 3911 trace "perl_reload: cancelling all extension coros";
3874 $_->cancel for values %EXT_CORO; 3912 $_->cancel for values %EXT_CORO;
3875 %EXT_CORO = (); 3913 %EXT_CORO = ();
3876 3914
3877 trace "removing commands"; 3915 trace "perl_reload: removing commands";
3878 %COMMAND = (); 3916 %COMMAND = ();
3879 3917
3880 trace "removing ext/exti commands"; 3918 trace "perl_reload: removing ext/exti commands";
3881 %EXTCMD = (); 3919 %EXTCMD = ();
3882 %EXTICMD = (); 3920 %EXTICMD = ();
3883 3921
3884 trace "unloading/nuking all extensions"; 3922 trace "perl_reload: unloading/nuking all extensions";
3885 for my $pkg (@EXTS) { 3923 for my $pkg (@EXTS) {
3886 trace "... unloading $pkg"; 3924 trace "... unloading $pkg";
3887 3925
3888 if (my $cb = $pkg->can ("unload")) { 3926 if (my $cb = $pkg->can ("unload")) {
3889 eval { 3927 eval {
3894 3932
3895 trace "... clearing $pkg"; 3933 trace "... clearing $pkg";
3896 clear_package $pkg; 3934 clear_package $pkg;
3897 } 3935 }
3898 3936
3899 trace "unloading all perl modules loaded from $LIBDIR"; 3937 trace "perl_reload: unloading all perl modules loaded from $LIBDIR";
3900 while (my ($k, $v) = each %INC) { 3938 while (my ($k, $v) = each %INC) {
3901 next unless $v =~ /^\Q$LIBDIR\E\/.*\.pm$/; 3939 next unless $v =~ /^\Q$LIBDIR\E\/.*\.pm$/;
3902 3940
3903 trace "... unloading $k"; 3941 trace "... unloading $k";
3904 delete $INC{$k}; 3942 delete $INC{$k};
3911 } 3949 }
3912 3950
3913 clear_package $k; 3951 clear_package $k;
3914 } 3952 }
3915 3953
3916 trace "getting rid of safe::, as good as possible"; 3954 trace "perl_reload: getting rid of safe::, as good as possible";
3917 clear_package "safe::$_" 3955 clear_package "safe::$_"
3918 for qw(cf::attachable cf::object cf::object::player cf::client cf::player cf::map cf::party cf::region); 3956 for qw(cf::attachable cf::object cf::object::player cf::client cf::player cf::map cf::party cf::region);
3919 3957
3920 trace "unloading cf.pm \"a bit\""; 3958 trace "perl_reload: unloading cf.pm \"a bit\"";
3921 delete $INC{"cf.pm"}; 3959 delete $INC{"cf.pm"};
3922 delete $INC{"cf/$_.pm"} for @EXTRA_MODULES; 3960 delete $INC{"cf/$_.pm"} for @EXTRA_MODULES;
3923 3961
3924 # don't, removes xs symbols, too, 3962 # don't, removes xs symbols, too,
3925 # and global variables created in xs 3963 # and global variables created in xs
3926 #clear_package __PACKAGE__; 3964 #clear_package __PACKAGE__;
3927 3965
3928 info "unload completed, starting to reload now"; 3966 info "perl_reload: unload completed, starting to reload now";
3929 3967
3930 trace "reloading cf.pm"; 3968 trace "perl_reload: reloading cf.pm";
3931 require cf; 3969 require cf;
3932 cf::_connect_to_perl_1; 3970 cf::_connect_to_perl_1;
3933 3971
3934 trace "loading config and database again"; 3972 trace "perl_reload: loading config and database again";
3935 cf::reload_config; 3973 cf::reload_config;
3936 3974
3937 trace "loading extensions"; 3975 trace "perl_reload: loading extensions";
3938 cf::load_extensions; 3976 cf::load_extensions;
3939 3977
3940 if ($REATTACH_ON_RELOAD) { 3978 if ($REATTACH_ON_RELOAD) {
3941 trace "reattaching attachments to objects/players"; 3979 trace "perl_reload: reattaching attachments to objects/players";
3942 _global_reattach; # objects, sockets 3980 _global_reattach; # objects, sockets
3943 trace "reattaching attachments to maps"; 3981 trace "perl_reload: reattaching attachments to maps";
3944 reattach $_ for values %MAP; 3982 reattach $_ for values %MAP;
3945 trace "reattaching attachments to players"; 3983 trace "perl_reload: reattaching attachments to players";
3946 reattach $_ for values %PLAYER; 3984 reattach $_ for values %PLAYER;
3947 } 3985 }
3948 3986
3949 trace "running post_init jobs"; 3987 cf::_post_init 1;
3950 (pop @POST_INIT)->(1) while @POST_INIT;
3951 3988
3952 trace "leaving sync_job"; 3989 trace "perl_reload: leaving sync_job";
3953 3990
3954 1 3991 1
3955 } or do { 3992 } or do {
3956 error $@; 3993 error $@;
3957 cf::cleanup "error while reloading, exiting."; 3994 cf::cleanup "perl_reload: error, exiting.";
3958 }; 3995 };
3959 3996
3960 info "reloaded";
3961 --$RELOAD; 3997 --$RELOAD;
3962 } 3998 }
3963 3999
3964 $t1 = AE::time - $t1; 4000 $t1 = AE::time - $t1;
3965 info "reload completed in ${t1}s\n"; 4001 info "perl_reload: completed in ${t1}s\n";
3966}; 4002};
3967 4003
3968our $RELOAD_WATCHER; # used only during reload 4004our $RELOAD_WATCHER; # used only during reload
3969 4005
3970sub reload_perl() { 4006sub reload_perl() {
3991 reload_perl; 4027 reload_perl;
3992 }; 4028 };
3993 } 4029 }
3994}; 4030};
3995 4031
3996unshift @INC, $LIBDIR; 4032#############################################################################
3997 4033
3998my $bug_warning = 0; 4034my $bug_warning = 0;
3999 4035
4000our @WAIT_FOR_TICK; 4036our @WAIT_FOR_TICK;
4001our @WAIT_FOR_TICK_BEGIN; 4037our @WAIT_FOR_TICK_BEGIN;
4002 4038
4003sub wait_for_tick { 4039sub wait_for_tick() {
4004 return Coro::cede if tick_inhibit || $Coro::current == $Coro::main; 4040 return Coro::cede if tick_inhibit || $Coro::current == $Coro::main;
4005 4041
4006 my $signal = new Coro::Signal; 4042 my $signal = new Coro::Signal;
4007 push @WAIT_FOR_TICK, $signal; 4043 push @WAIT_FOR_TICK, $signal;
4008 $signal->wait; 4044 $signal->wait;
4009} 4045}
4010 4046
4011sub wait_for_tick_begin { 4047sub wait_for_tick_begin() {
4012 return Coro::cede if tick_inhibit || $Coro::current == $Coro::main; 4048 return Coro::cede if tick_inhibit || $Coro::current == $Coro::main;
4013 4049
4014 my $signal = new Coro::Signal; 4050 my $signal = new Coro::Signal;
4015 push @WAIT_FOR_TICK_BEGIN, $signal; 4051 push @WAIT_FOR_TICK_BEGIN, $signal;
4016 $signal->wait; 4052 $signal->wait;
4103 IO::AIO::min_parallel 8; 4139 IO::AIO::min_parallel 8;
4104 IO::AIO::max_poll_time $TICK * 0.1; 4140 IO::AIO::max_poll_time $TICK * 0.1;
4105 undef $AnyEvent::AIO::WATCHER; 4141 undef $AnyEvent::AIO::WATCHER;
4106} 4142}
4107 4143
4108my $_log_backtrace; 4144our $_log_backtrace;
4145our $_log_backtrace_last;
4109 4146
4110sub _log_backtrace { 4147sub _log_backtrace {
4111 my ($msg, @addr) = @_; 4148 my ($msg, @addr) = @_;
4112 4149
4113 $msg =~ s/\n//; 4150 $msg =~ s/\n$//;
4114 4151
4152 if ($_log_backtrace_last eq $msg) {
4153 LOG llevInfo, "[ABT] $msg\n";
4154 LOG llevInfo, "[ABT] [duplicate, suppressed]\n";
4115 # limit the # of concurrent backtraces 4155 # limit the # of concurrent backtraces
4116 if ($_log_backtrace < 2) { 4156 } elsif ($_log_backtrace < 2) {
4157 $_log_backtrace_last = $msg;
4117 ++$_log_backtrace; 4158 ++$_log_backtrace;
4118 my $perl_bt = Carp::longmess $msg; 4159 my $perl_bt = Carp::longmess $msg;
4119 async { 4160 async {
4120 $Coro::current->{desc} = "abt $msg"; 4161 $Coro::current->{desc} = "abt $msg";
4121 4162
4141 LOG llevInfo, "[ABT] $_\n" for @bt; 4182 LOG llevInfo, "[ABT] $_\n" for @bt;
4142 --$_log_backtrace; 4183 --$_log_backtrace;
4143 }; 4184 };
4144 } else { 4185 } else {
4145 LOG llevInfo, "[ABT] $msg\n"; 4186 LOG llevInfo, "[ABT] $msg\n";
4146 LOG llevInfo, "[ABT] [suppressed]\n"; 4187 LOG llevInfo, "[ABT] [overload, suppressed]\n";
4147 } 4188 }
4148} 4189}
4149 4190
4150# load additional modules 4191# load additional modules
4151require "cf/$_.pm" for @EXTRA_MODULES; 4192require "cf/$_.pm" for @EXTRA_MODULES;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines