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.542 by root, Wed May 5 09:05:03 2010 UTC vs.
Revision 1.558 by root, Tue Oct 5 22:35:30 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 {
1641 my $name = $pl->ob->name; 1679 my $name = $pl->ob->name;
1642 1680
1643 $pl->{deny_save} = 1; 1681 $pl->{deny_save} = 1;
1644 $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
1645 1683
1646 $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1) if $pl->active; 1684 $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1) if $pl->ns;
1647 $pl->deactivate; 1685 $pl->deactivate;
1686
1648 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;
1649 $pl->invoke (cf::EVENT_PLAYER_QUIT); 1688 $pl->invoke (cf::EVENT_PLAYER_QUIT) if $pl->ns;
1689 ext::highscore::check ($pl->ob);
1690
1650 $pl->ns->destroy if $pl->ns; 1691 $pl->ns->destroy if $pl->ns;
1651 1692
1652 my $path = playerdir $pl; 1693 my $path = playerdir $pl;
1653 my $temp = "$path~$cf::RUNTIME~deleting~"; 1694 my $temp = "$path~$cf::RUNTIME~deleting~";
1654 aio_rename $path, $temp; 1695 aio_rename $path, $temp;
1820sub generate_random_map { 1861sub generate_random_map {
1821 my ($self, $rmp) = @_; 1862 my ($self, $rmp) = @_;
1822 1863
1823 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
1824 1865
1825 # mit "rum" bekleckern, nicht
1826 $self->_create_random_map ( 1866 $self->_create_random_map ($rmp);
1827 $rmp->{wallstyle}, $rmp->{wall_name}, $rmp->{floorstyle}, $rmp->{monsterstyle},
1828 $rmp->{treasurestyle}, $rmp->{layoutstyle}, $rmp->{doorstyle}, $rmp->{decorstyle}, $rmp->{miningstyle},
1829 $rmp->{origin_map}, $rmp->{final_map}, $rmp->{exitstyle}, $rmp->{this_map},
1830 $rmp->{exit_on_final_map},
1831 $rmp->{xsize}, $rmp->{ysize},
1832 $rmp->{expand2x}, $rmp->{layoutoptions1}, $rmp->{layoutoptions2}, $rmp->{layoutoptions3},
1833 $rmp->{symmetry}, $rmp->{difficulty}, $rmp->{difficulty_given}, $rmp->{difficulty_increase},
1834 $rmp->{dungeon_level}, $rmp->{dungeon_depth}, $rmp->{decoroptions}, $rmp->{orientation},
1835 $rmp->{origin_y}, $rmp->{origin_x}, $rmp->{random_seed}, $rmp->{total_map_hp},
1836 $rmp->{map_layout_style}, $rmp->{treasureoptions}, $rmp->{symmetry_used},
1837 (cf::region::find $rmp->{region}), $rmp->{custom}
1838 )
1839} 1867}
1840 1868
1841=item cf::map->register ($regex, $prio) 1869=item cf::map->register ($regex, $prio)
1842 1870
1843Register 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
1869} 1897}
1870 1898
1871sub normalise { 1899sub normalise {
1872 my ($path, $base) = @_; 1900 my ($path, $base) = @_;
1873 1901
1874 $path = "$path"; # make sure its a string 1902 $path = "$path"; # make sure it's a string
1875 1903
1876 $path =~ s/\.map$//; 1904 $path =~ s/\.map$//;
1877 1905
1878 # map plan: 1906 # map plan:
1879 # 1907 #
1894 $base =~ s{[^/]+/?$}{}; 1922 $base =~ s{[^/]+/?$}{};
1895 $path = "$base/$path"; 1923 $path = "$base/$path";
1896 } 1924 }
1897 1925
1898 for ($path) { 1926 for ($path) {
1899 redo if s{//}{/};
1900 redo if s{/\.?/}{/}; 1927 redo if s{/\.?/}{/};
1901 redo if s{/[^/]+/\.\./}{/}; 1928 redo if s{/[^/]+/\.\./}{/};
1902 } 1929 }
1903 1930
1904 $path 1931 $path
1918 $self->init; # pass $1 etc. 1945 $self->init; # pass $1 etc.
1919 return $self; 1946 return $self;
1920 } 1947 }
1921 } 1948 }
1922 1949
1923 Carp::cluck "unable to resolve path '$path' (base '$base')."; 1950 Carp::cluck "unable to resolve path '$path' (base '$base')";
1924 () 1951 ()
1925} 1952}
1926 1953
1927sub init { 1954sub init {
1928 my ($self) = @_; 1955 my ($self) = @_;
2050} 2077}
2051 2078
2052sub find; 2079sub find;
2053sub find { 2080sub find {
2054 my ($path, $origin) = @_; 2081 my ($path, $origin) = @_;
2082
2083 cf::cede_to_tick;
2055 2084
2056 $path = normalise $path, $origin && $origin->path; 2085 $path = normalise $path, $origin && $origin->path;
2057 2086
2058 my $guard1 = cf::lock_acquire "map_data:$path";#d#remove 2087 my $guard1 = cf::lock_acquire "map_data:$path";#d#remove
2059 my $guard2 = cf::lock_acquire "map_find:$path"; 2088 my $guard2 = cf::lock_acquire "map_find:$path";
2144 2173
2145 $self->in_memory (cf::MAP_ACTIVE); 2174 $self->in_memory (cf::MAP_ACTIVE);
2146 } 2175 }
2147 2176
2148 $self->post_load; 2177 $self->post_load;
2178
2179 1
2149} 2180}
2150 2181
2151# customize the map for a given player, i.e. 2182# customize the map for a given player, i.e.
2152# return the _real_ map. used by e.g. per-player 2183# return the _real_ map. used by e.g. per-player
2153# maps to change the path to ~playername/mappath 2184# maps to change the path to ~playername/mappath
3357=cut 3388=cut
3358 3389
3359############################################################################# 3390#############################################################################
3360# the server's init and main functions 3391# the server's init and main functions
3361 3392
3362# async inc loader. yay.
3363sub inc_loader {
3364 my $mod = $_[1];
3365
3366 if (in_main && !tick_inhibit) {
3367 Carp::cluck "ERROR: attempted synchronous perl module load ($mod)";
3368 } else {
3369 debug "loading perl module $mod\n";
3370 }
3371
3372 # 1. find real file
3373 for my $dir (@ORIG_INC) {
3374 ref $dir and next;
3375 0 <= Coro::AIO::aio_load "$dir/$mod", my $data
3376 or next;
3377
3378 $data = "#line 1 $dir/$mod\n$data";
3379
3380 open my $fh, "<", \$data or die;
3381
3382 return $fh;
3383 }
3384
3385 ()
3386}
3387
3388sub init_inc {
3389 # save original @INC
3390 @ORIG_INC = ($LIBDIR, @INC) unless @ORIG_INC;
3391
3392 # make sure we can do scalar-opens
3393 open my $dummy, "<", \my $dummy2;
3394
3395 # execute some stuff so perl load's some of the core modules
3396 /Ü/ =~ /ü/i;
3397 eval { &Storable::nstore_fd };
3398
3399 @INC = (\&inc_loader, @ORIG_INC); # @ORIG_INC is needed for DynaLoader, AutoLoad etc.
3400
3401 debug "module loading will be asynchronous from this point on.";
3402}
3403
3404sub load_facedata($) { 3393sub load_facedata($) {
3405 my ($path) = @_; 3394 my ($path) = @_;
3406 3395
3407 # 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
3408 # for this (global event?) 3397 # for this (global event?)
3410 3399
3411 my $enc = JSON::XS->new->utf8->canonical->relaxed; 3400 my $enc = JSON::XS->new->utf8->canonical->relaxed;
3412 3401
3413 trace "loading facedata from $path\n"; 3402 trace "loading facedata from $path\n";
3414 3403
3415 my $facedata;
3416 0 < aio_load $path, $facedata 3404 0 < aio_load $path, my $facedata
3417 or die "$path: $!"; 3405 or die "$path: $!";
3418 3406
3419 $facedata = Coro::Storable::thaw $facedata; 3407 $facedata = Coro::Storable::thaw $facedata;
3420 3408
3421 $facedata->{version} == 2 3409 $facedata->{version} == 2
3438 3426
3439 cf::face::set_visibility $idx, $info->{visibility}; 3427 cf::face::set_visibility $idx, $info->{visibility};
3440 cf::face::set_magicmap $idx, $info->{magicmap}; 3428 cf::face::set_magicmap $idx, $info->{magicmap};
3441 cf::face::set_data $idx, 0, $info->{data32}, $info->{hash32}; 3429 cf::face::set_data $idx, 0, $info->{data32}, $info->{hash32};
3442 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} ;
3443 3432
3444 cf::cede_to_tick; 3433 cf::cede_to_tick;
3445 } 3434 }
3446 3435
3447 while (my ($face, $info) = each %$faces) { 3436 while (my ($face, $info) = each %$faces) {
3565} 3554}
3566 3555
3567sub reload_resources { 3556sub reload_resources {
3568 trace "reloading resource files...\n"; 3557 trace "reloading resource files...\n";
3569 3558
3559 reload_exp_table;
3560 reload_materials;
3570 reload_facedata; 3561 reload_facedata;
3571 reload_sound; 3562 reload_sound;
3572 reload_archetypes; 3563 reload_archetypes;
3573 reload_regions; 3564 reload_regions;
3574 reload_treasures; 3565 reload_treasures;
3577} 3568}
3578 3569
3579sub reload_config { 3570sub reload_config {
3580 trace "reloading config file...\n"; 3571 trace "reloading config file...\n";
3581 3572
3582 open my $fh, "<:utf8", "$CONFDIR/config" 3573 0 < aio_load "$CONFDIR/config", my $config
3583 or return; 3574 or die "$CONFDIR/config: $!";
3584 3575
3585 local $/; 3576 utf8::decode $config;
3586 *CFG = YAML::XS::Load scalar <$fh>; 3577 *CFG = yaml_load $config;
3587 3578
3588 $EMERGENCY_POSITION = $CFG{emergency_position} || ["/world/world_104_115", 49, 38]; 3579 $EMERGENCY_POSITION = $CFG{emergency_position} || ["/world/world_104_115", 49, 38];
3589 3580
3590 $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};
3591 $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};
3595 $CFG{mlockall} ? eval "mlockall()" : eval "munlockall()" 3586 $CFG{mlockall} ? eval "mlockall()" : eval "munlockall()"
3596 and die "WARNING: m(un)lockall failed: $!\n"; 3587 and die "WARNING: m(un)lockall failed: $!\n";
3597 }; 3588 };
3598 warn $@ if $@; 3589 warn $@ if $@;
3599 } 3590 }
3600
3601 trace "finished reloading resource files\n";
3602} 3591}
3603 3592
3604sub pidfile() { 3593sub pidfile() {
3605 sysopen my $fh, $PIDFILE, O_RDWR | O_CREAT 3594 sysopen my $fh, $PIDFILE, O_RDWR | O_CREAT
3606 or die "$PIDFILE: $!"; 3595 or die "$PIDFILE: $!";
3649 }; 3638 };
3650 3639
3651 evthread_start IO::AIO::poll_fileno; 3640 evthread_start IO::AIO::poll_fileno;
3652 3641
3653 cf::sync_job { 3642 cf::sync_job {
3654 init_inc; 3643 cf::incloader::init ();
3655 3644
3656 cf::init_experience;
3657 cf::init_anim; 3645 cf::init_anim;
3658 cf::init_attackmess; 3646 cf::init_attackmess;
3659 cf::init_dynamic; 3647 cf::init_dynamic;
3660 3648
3661 cf::load_settings; 3649 cf::load_settings;
3662 cf::load_materials;
3663 3650
3664 reload_resources; 3651 reload_resources;
3665 reload_config; 3652 reload_config;
3666 db_init; 3653 db_init;
3667 3654
3679 3666
3680 # no (long-running) fork's whatsoever before this point(!) 3667 # no (long-running) fork's whatsoever before this point(!)
3681 use POSIX (); 3668 use POSIX ();
3682 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};
3683 3670
3684 (pop @POST_INIT)->(0) while @POST_INIT; 3671 cf::_post_init 0;
3685 }; 3672 };
3686 3673
3687 cf::object::thawer::errors_are_fatal 0; 3674 cf::object::thawer::errors_are_fatal 0;
3688 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";
3689 3676
3901 } 3888 }
3902} 3889}
3903 3890
3904sub do_reload_perl() { 3891sub do_reload_perl() {
3905 # can/must only be called in main 3892 # can/must only be called in main
3906 if (in_main) { 3893 unless (in_main) {
3907 error "can only reload from main coroutine"; 3894 error "can only reload from main coroutine";
3908 return; 3895 return;
3909 } 3896 }
3910 3897
3911 return if $RELOAD++; 3898 return if $RELOAD++;
3912 3899
3913 my $t1 = AE::time; 3900 my $t1 = AE::time;
3914 3901
3915 while ($RELOAD) { 3902 while ($RELOAD) {
3903 cf::get_slot 0.1, -1, "reload_perl";
3916 info "reloading..."; 3904 info "perl_reload: reloading...";
3917 3905
3918 trace "entering sync_job"; 3906 trace "perl_reload: entering sync_job";
3919 3907
3920 cf::sync_job { 3908 cf::sync_job {
3921 cf::emergency_save; 3909 #cf::emergency_save;
3922 3910
3923 trace "cancelling all extension coros"; 3911 trace "perl_reload: cancelling all extension coros";
3924 $_->cancel for values %EXT_CORO; 3912 $_->cancel for values %EXT_CORO;
3925 %EXT_CORO = (); 3913 %EXT_CORO = ();
3926 3914
3927 trace "removing commands"; 3915 trace "perl_reload: removing commands";
3928 %COMMAND = (); 3916 %COMMAND = ();
3929 3917
3930 trace "removing ext/exti commands"; 3918 trace "perl_reload: removing ext/exti commands";
3931 %EXTCMD = (); 3919 %EXTCMD = ();
3932 %EXTICMD = (); 3920 %EXTICMD = ();
3933 3921
3934 trace "unloading/nuking all extensions"; 3922 trace "perl_reload: unloading/nuking all extensions";
3935 for my $pkg (@EXTS) { 3923 for my $pkg (@EXTS) {
3936 trace "... unloading $pkg"; 3924 trace "... unloading $pkg";
3937 3925
3938 if (my $cb = $pkg->can ("unload")) { 3926 if (my $cb = $pkg->can ("unload")) {
3939 eval { 3927 eval {
3944 3932
3945 trace "... clearing $pkg"; 3933 trace "... clearing $pkg";
3946 clear_package $pkg; 3934 clear_package $pkg;
3947 } 3935 }
3948 3936
3949 trace "unloading all perl modules loaded from $LIBDIR"; 3937 trace "perl_reload: unloading all perl modules loaded from $LIBDIR";
3950 while (my ($k, $v) = each %INC) { 3938 while (my ($k, $v) = each %INC) {
3951 next unless $v =~ /^\Q$LIBDIR\E\/.*\.pm$/; 3939 next unless $v =~ /^\Q$LIBDIR\E\/.*\.pm$/;
3952 3940
3953 trace "... unloading $k"; 3941 trace "... unloading $k";
3954 delete $INC{$k}; 3942 delete $INC{$k};
3961 } 3949 }
3962 3950
3963 clear_package $k; 3951 clear_package $k;
3964 } 3952 }
3965 3953
3966 trace "getting rid of safe::, as good as possible"; 3954 trace "perl_reload: getting rid of safe::, as good as possible";
3967 clear_package "safe::$_" 3955 clear_package "safe::$_"
3968 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);
3969 3957
3970 trace "unloading cf.pm \"a bit\""; 3958 trace "perl_reload: unloading cf.pm \"a bit\"";
3971 delete $INC{"cf.pm"}; 3959 delete $INC{"cf.pm"};
3972 delete $INC{"cf/$_.pm"} for @EXTRA_MODULES; 3960 delete $INC{"cf/$_.pm"} for @EXTRA_MODULES;
3973 3961
3974 # don't, removes xs symbols, too, 3962 # don't, removes xs symbols, too,
3975 # and global variables created in xs 3963 # and global variables created in xs
3976 #clear_package __PACKAGE__; 3964 #clear_package __PACKAGE__;
3977 3965
3978 info "unload completed, starting to reload now"; 3966 info "perl_reload: unload completed, starting to reload now";
3979 3967
3980 trace "reloading cf.pm"; 3968 trace "perl_reload: reloading cf.pm";
3981 require cf; 3969 require cf;
3982 cf::_connect_to_perl_1; 3970 cf::_connect_to_perl_1;
3983 3971
3984 trace "loading config and database again"; 3972 trace "perl_reload: loading config and database again";
3985 cf::reload_config; 3973 cf::reload_config;
3986 3974
3987 trace "loading extensions"; 3975 trace "perl_reload: loading extensions";
3988 cf::load_extensions; 3976 cf::load_extensions;
3989 3977
3990 if ($REATTACH_ON_RELOAD) { 3978 if ($REATTACH_ON_RELOAD) {
3991 trace "reattaching attachments to objects/players"; 3979 trace "perl_reload: reattaching attachments to objects/players";
3992 _global_reattach; # objects, sockets 3980 _global_reattach; # objects, sockets
3993 trace "reattaching attachments to maps"; 3981 trace "perl_reload: reattaching attachments to maps";
3994 reattach $_ for values %MAP; 3982 reattach $_ for values %MAP;
3995 trace "reattaching attachments to players"; 3983 trace "perl_reload: reattaching attachments to players";
3996 reattach $_ for values %PLAYER; 3984 reattach $_ for values %PLAYER;
3997 } 3985 }
3998 3986
3999 trace "running post_init jobs"; 3987 cf::_post_init 1;
4000 (pop @POST_INIT)->(1) while @POST_INIT;
4001 3988
4002 trace "leaving sync_job"; 3989 trace "perl_reload: leaving sync_job";
4003 3990
4004 1 3991 1
4005 } or do { 3992 } or do {
4006 error $@; 3993 error $@;
4007 cf::cleanup "error while reloading, exiting."; 3994 cf::cleanup "perl_reload: error, exiting.";
4008 }; 3995 };
4009 3996
4010 info "reloaded";
4011 --$RELOAD; 3997 --$RELOAD;
4012 } 3998 }
4013 3999
4014 $t1 = AE::time - $t1; 4000 $t1 = AE::time - $t1;
4015 info "reload completed in ${t1}s\n"; 4001 info "perl_reload: completed in ${t1}s\n";
4016}; 4002};
4017 4003
4018our $RELOAD_WATCHER; # used only during reload 4004our $RELOAD_WATCHER; # used only during reload
4019 4005
4020sub reload_perl() { 4006sub reload_perl() {
4048my $bug_warning = 0; 4034my $bug_warning = 0;
4049 4035
4050our @WAIT_FOR_TICK; 4036our @WAIT_FOR_TICK;
4051our @WAIT_FOR_TICK_BEGIN; 4037our @WAIT_FOR_TICK_BEGIN;
4052 4038
4053sub wait_for_tick { 4039sub wait_for_tick() {
4054 return Coro::cede if tick_inhibit || $Coro::current == $Coro::main; 4040 return Coro::cede if tick_inhibit || $Coro::current == $Coro::main;
4055 4041
4056 my $signal = new Coro::Signal; 4042 my $signal = new Coro::Signal;
4057 push @WAIT_FOR_TICK, $signal; 4043 push @WAIT_FOR_TICK, $signal;
4058 $signal->wait; 4044 $signal->wait;
4059} 4045}
4060 4046
4061sub wait_for_tick_begin { 4047sub wait_for_tick_begin() {
4062 return Coro::cede if tick_inhibit || $Coro::current == $Coro::main; 4048 return Coro::cede if tick_inhibit || $Coro::current == $Coro::main;
4063 4049
4064 my $signal = new Coro::Signal; 4050 my $signal = new Coro::Signal;
4065 push @WAIT_FOR_TICK_BEGIN, $signal; 4051 push @WAIT_FOR_TICK_BEGIN, $signal;
4066 $signal->wait; 4052 $signal->wait;
4153 IO::AIO::min_parallel 8; 4139 IO::AIO::min_parallel 8;
4154 IO::AIO::max_poll_time $TICK * 0.1; 4140 IO::AIO::max_poll_time $TICK * 0.1;
4155 undef $AnyEvent::AIO::WATCHER; 4141 undef $AnyEvent::AIO::WATCHER;
4156} 4142}
4157 4143
4158my $_log_backtrace; 4144our $_log_backtrace;
4145our $_log_backtrace_last;
4159 4146
4160sub _log_backtrace { 4147sub _log_backtrace {
4161 my ($msg, @addr) = @_; 4148 my ($msg, @addr) = @_;
4162 4149
4163 $msg =~ s/\n//; 4150 $msg =~ s/\n$//;
4164 4151
4152 if ($_log_backtrace_last eq $msg) {
4153 LOG llevInfo, "[ABT] $msg\n";
4154 LOG llevInfo, "[ABT] [duplicate, suppressed]\n";
4165 # limit the # of concurrent backtraces 4155 # limit the # of concurrent backtraces
4166 if ($_log_backtrace < 2) { 4156 } elsif ($_log_backtrace < 2) {
4157 $_log_backtrace_last = $msg;
4167 ++$_log_backtrace; 4158 ++$_log_backtrace;
4168 my $perl_bt = Carp::longmess $msg; 4159 my $perl_bt = Carp::longmess $msg;
4169 async { 4160 async {
4170 $Coro::current->{desc} = "abt $msg"; 4161 $Coro::current->{desc} = "abt $msg";
4171 4162
4191 LOG llevInfo, "[ABT] $_\n" for @bt; 4182 LOG llevInfo, "[ABT] $_\n" for @bt;
4192 --$_log_backtrace; 4183 --$_log_backtrace;
4193 }; 4184 };
4194 } else { 4185 } else {
4195 LOG llevInfo, "[ABT] $msg\n"; 4186 LOG llevInfo, "[ABT] $msg\n";
4196 LOG llevInfo, "[ABT] [suppressed]\n"; 4187 LOG llevInfo, "[ABT] [overload, suppressed]\n";
4197 } 4188 }
4198} 4189}
4199 4190
4200# load additional modules 4191# load additional modules
4201require "cf/$_.pm" for @EXTRA_MODULES; 4192require "cf/$_.pm" for @EXTRA_MODULES;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines