--- deliantra/server/lib/cf.pm 2007/02/13 16:23:32 1.211 +++ deliantra/server/lib/cf.pm 2007/02/13 19:25:44 1.212 @@ -358,8 +358,6 @@ } sub write_runtime { - $TICK_WATCHER->is_active or cf::cleanup "mainloop frozen but runtime active", 1; - my $runtime = cf::localdir . "/runtime"; my $fh = aio_open "$runtime~", O_WRONLY | O_CREAT, 0644 @@ -2374,12 +2372,16 @@ warn "reloading..."; - warn "cancelling server ticker"; - $TICK_WATCHER->cancel; + warn "entering sync_job"; + + sync_job { + write_runtime; + cf::emergency_save; + write_runtime; - cf::emergency_save; + warn "syncing database to disk"; + BDB::db_env_txn_checkpoint $DB_ENV; - eval { # if anything goes wrong in here, we should simply crash as we already saved warn "cancelling all WF_AUTOCANCEL watchers"; @@ -2387,9 +2389,6 @@ $_->cancel if $_->data & WF_AUTOCANCEL; } - warn "syncing database to disk"; - BDB::db_env_txn_checkpoint $DB_ENV, 0, 0, 0, sub { }; - warn "flushing outstanding aio requests"; for (;;) { BDB::flush; @@ -2472,16 +2471,14 @@ warn "loading reloadable resources"; load_resources; - warn "restarting server ticker"; + warn "leaving sync_job"; - $TICK_WATCHER->start; - }; - - if ($@) { + 1 + } or do { warn $@; warn "error while reloading, exiting."; exit 1; - } + }; warn "reloaded"; }; @@ -2535,9 +2532,6 @@ $WAIT_FOR_TICK->broadcast; $WAIT_FOR_TICK_ONE->send if $WAIT_FOR_TICK_ONE->awaited; - Event::sweep; - Coro::cede_notself; - # my $AFTER = Event::time; # warn $AFTER - $NOW;#d# @@ -2617,12 +2611,17 @@ $WRITE_RUNTIME_WATCHER = Event->timer ( reentrant => 0, data => WF_AUTOCANCEL, + parked => 1, after => 1, interval => 10, prio => 6, # keep it lowest so it acts like a watchdog - cb => Coro::unblock_sub { - write_runtime - or warn "ERROR: unable to write runtime file: $!"; + cb => sub { + $TICK_WATCHER->is_active or cf::cleanup "mainloop frozen but runtime active", 1; + + Coro::async_pool { + write_runtime + or warn "ERROR: unable to write runtime file: $!"; + }; }, );