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.210 by root, Mon Feb 12 01:32:49 2007 UTC vs.
Revision 1.212 by root, Tue Feb 13 19:25:44 2007 UTC

2354 }; 2354 };
2355 2355
2356 warn "leave emergency perl save\n"; 2356 warn "leave emergency perl save\n";
2357} 2357}
2358 2358
2359sub post_cleanup {
2360 my ($make_core) = @_;
2361
2362 warn Carp::longmess "post_cleanup backtrace"
2363 if $make_core;
2364}
2365
2359sub reload() { 2366sub reload() {
2360 # can/must only be called in main 2367 # can/must only be called in main
2361 if ($Coro::current != $Coro::main) { 2368 if ($Coro::current != $Coro::main) {
2362 warn "can only reload from main coroutine"; 2369 warn "can only reload from main coroutine";
2363 return; 2370 return;
2364 } 2371 }
2365 2372
2366 warn "reloading..."; 2373 warn "reloading...";
2367 2374
2368 warn "cancelling server ticker"; 2375 warn "entering sync_job";
2369 $TICK_WATCHER->cancel;
2370 2376
2377 sync_job {
2378 write_runtime;
2371 cf::emergency_save; 2379 cf::emergency_save;
2380 write_runtime;
2372 2381
2373 eval { 2382 warn "syncing database to disk";
2383 BDB::db_env_txn_checkpoint $DB_ENV;
2384
2374 # if anything goes wrong in here, we should simply crash as we already saved 2385 # if anything goes wrong in here, we should simply crash as we already saved
2375 2386
2376 warn "cancelling all WF_AUTOCANCEL watchers"; 2387 warn "cancelling all WF_AUTOCANCEL watchers";
2377 for (Event::all_watchers) { 2388 for (Event::all_watchers) {
2378 $_->cancel if $_->data & WF_AUTOCANCEL; 2389 $_->cancel if $_->data & WF_AUTOCANCEL;
2379 } 2390 }
2380
2381 warn "syncing database to disk";
2382 BDB::db_env_txn_checkpoint $DB_ENV, 0, 0, 0, sub { };
2383 2391
2384 warn "flushing outstanding aio requests"; 2392 warn "flushing outstanding aio requests";
2385 for (;;) { 2393 for (;;) {
2386 BDB::flush; 2394 BDB::flush;
2387 IO::AIO::flush; 2395 IO::AIO::flush;
2461 reattach $_ for values %MAP; 2469 reattach $_ for values %MAP;
2462 2470
2463 warn "loading reloadable resources"; 2471 warn "loading reloadable resources";
2464 load_resources; 2472 load_resources;
2465 2473
2466 warn "restarting server ticker"; 2474 warn "leaving sync_job";
2467 2475
2468 $TICK_WATCHER->start; 2476 1
2469 }; 2477 } or do {
2470
2471 if ($@) {
2472 warn $@; 2478 warn $@;
2473 warn "error while reloading, exiting."; 2479 warn "error while reloading, exiting.";
2474 exit 1; 2480 exit 1;
2475 } 2481 };
2476 2482
2477 warn "reloaded"; 2483 warn "reloaded";
2478}; 2484};
2479 2485
2480our $RELOAD_WATCHER; # used only during reload 2486our $RELOAD_WATCHER; # used only during reload
2524 $NEXT_TICK += $TICK; 2530 $NEXT_TICK += $TICK;
2525 2531
2526 $WAIT_FOR_TICK->broadcast; 2532 $WAIT_FOR_TICK->broadcast;
2527 $WAIT_FOR_TICK_ONE->send if $WAIT_FOR_TICK_ONE->awaited; 2533 $WAIT_FOR_TICK_ONE->send if $WAIT_FOR_TICK_ONE->awaited;
2528 2534
2529 Event::sweep;
2530 Coro::cede_notself;
2531
2532# my $AFTER = Event::time; 2535# my $AFTER = Event::time;
2533# warn $AFTER - $NOW;#d# 2536# warn $AFTER - $NOW;#d#
2534 2537
2535 # if we are delayed by four ticks or more, skip them all 2538 # if we are delayed by four ticks or more, skip them all
2536 $NEXT_TICK = Event::time if Event::time >= $NEXT_TICK + $TICK * 4; 2539 $NEXT_TICK = Event::time if Event::time >= $NEXT_TICK + $TICK * 4;
2606} 2609}
2607 2610
2608$WRITE_RUNTIME_WATCHER = Event->timer ( 2611$WRITE_RUNTIME_WATCHER = Event->timer (
2609 reentrant => 0, 2612 reentrant => 0,
2610 data => WF_AUTOCANCEL, 2613 data => WF_AUTOCANCEL,
2614 parked => 1,
2611 after => 1, 2615 after => 1,
2612 interval => 10, 2616 interval => 10,
2613 prio => 6, # keep it lowest so it acts like a watchdog 2617 prio => 6, # keep it lowest so it acts like a watchdog
2614 cb => Coro::unblock_sub { 2618 cb => sub {
2619 $TICK_WATCHER->is_active or cf::cleanup "mainloop frozen but runtime active", 1;
2620
2621 Coro::async_pool {
2615 write_runtime 2622 write_runtime
2616 or warn "ERROR: unable to write runtime file: $!"; 2623 or warn "ERROR: unable to write runtime file: $!";
2624 };
2617 }, 2625 },
2618); 2626);
2619 2627
2620END { cf::emergency_save } 2628END { cf::emergency_save }
2621 2629

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines