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.211 by root, Tue Feb 13 16:23:32 2007 UTC vs.
Revision 1.213 by root, Tue Feb 13 20:01:04 2007 UTC

356 356
357 $coro 357 $coro
358} 358}
359 359
360sub write_runtime { 360sub write_runtime {
361 $TICK_WATCHER->is_active or cf::cleanup "mainloop frozen but runtime active", 1;
362
363 my $runtime = cf::localdir . "/runtime"; 361 my $runtime = cf::localdir . "/runtime";
364 362
365 my $fh = aio_open "$runtime~", O_WRONLY | O_CREAT, 0644 363 my $fh = aio_open "$runtime~", O_WRONLY | O_CREAT, 0644
366 or return; 364 or return;
367 365
2302 cfg_load; 2300 cfg_load;
2303 db_init; 2301 db_init;
2304 load_extensions; 2302 load_extensions;
2305 2303
2306 $TICK_WATCHER->start; 2304 $TICK_WATCHER->start;
2305 $WRITE_RUNTIME_WATCHER->start;
2307 Event::loop; 2306 Event::loop;
2308} 2307}
2309 2308
2310############################################################################# 2309#############################################################################
2311# initialisation and cleanup 2310# initialisation and cleanup
2372 return; 2371 return;
2373 } 2372 }
2374 2373
2375 warn "reloading..."; 2374 warn "reloading...";
2376 2375
2377 warn "cancelling server ticker"; 2376 warn "entering sync_job";
2378 $TICK_WATCHER->cancel;
2379 2377
2378 cf::sync_job {
2379 cf::write_runtime;
2380 cf::emergency_save; 2380 cf::emergency_save;
2381 cf::write_runtime;
2381 2382
2382 eval { 2383 warn "syncing database to disk";
2384 BDB::db_env_txn_checkpoint $DB_ENV;
2385
2383 # if anything goes wrong in here, we should simply crash as we already saved 2386 # if anything goes wrong in here, we should simply crash as we already saved
2384 2387
2385 warn "cancelling all WF_AUTOCANCEL watchers"; 2388 warn "cancelling all WF_AUTOCANCEL watchers";
2386 for (Event::all_watchers) { 2389 for (Event::all_watchers) {
2387 $_->cancel if $_->data & WF_AUTOCANCEL; 2390 $_->cancel if $_->data & WF_AUTOCANCEL;
2388 } 2391 }
2389
2390 warn "syncing database to disk";
2391 BDB::db_env_txn_checkpoint $DB_ENV, 0, 0, 0, sub { };
2392 2392
2393 warn "flushing outstanding aio requests"; 2393 warn "flushing outstanding aio requests";
2394 for (;;) { 2394 for (;;) {
2395 BDB::flush; 2395 BDB::flush;
2396 IO::AIO::flush; 2396 IO::AIO::flush;
2470 reattach $_ for values %MAP; 2470 reattach $_ for values %MAP;
2471 2471
2472 warn "loading reloadable resources"; 2472 warn "loading reloadable resources";
2473 load_resources; 2473 load_resources;
2474 2474
2475 warn "restarting server ticker"; 2475 warn "leaving sync_job";
2476 2476
2477 $TICK_WATCHER->start; 2477 1
2478 }; 2478 } or do {
2479
2480 if ($@) {
2481 warn $@; 2479 warn $@;
2482 warn "error while reloading, exiting."; 2480 warn "error while reloading, exiting.";
2483 exit 1; 2481 exit 1;
2484 } 2482 };
2485 2483
2486 warn "reloaded"; 2484 warn "reloaded";
2487}; 2485};
2488 2486
2489our $RELOAD_WATCHER; # used only during reload 2487our $RELOAD_WATCHER; # used only during reload
2533 $NEXT_TICK += $TICK; 2531 $NEXT_TICK += $TICK;
2534 2532
2535 $WAIT_FOR_TICK->broadcast; 2533 $WAIT_FOR_TICK->broadcast;
2536 $WAIT_FOR_TICK_ONE->send if $WAIT_FOR_TICK_ONE->awaited; 2534 $WAIT_FOR_TICK_ONE->send if $WAIT_FOR_TICK_ONE->awaited;
2537 2535
2538 Event::sweep;
2539 Coro::cede_notself;
2540
2541# my $AFTER = Event::time; 2536# my $AFTER = Event::time;
2542# warn $AFTER - $NOW;#d# 2537# warn $AFTER - $NOW;#d#
2543 2538
2544 # if we are delayed by four ticks or more, skip them all 2539 # if we are delayed by four ticks or more, skip them all
2545 $NEXT_TICK = Event::time if Event::time >= $NEXT_TICK + $TICK * 4; 2540 $NEXT_TICK = Event::time if Event::time >= $NEXT_TICK + $TICK * 4;
2615} 2610}
2616 2611
2617$WRITE_RUNTIME_WATCHER = Event->timer ( 2612$WRITE_RUNTIME_WATCHER = Event->timer (
2618 reentrant => 0, 2613 reentrant => 0,
2619 data => WF_AUTOCANCEL, 2614 data => WF_AUTOCANCEL,
2615 parked => 1,
2620 after => 1, 2616 after => 1,
2621 interval => 10, 2617 interval => 10,
2622 prio => 6, # keep it lowest so it acts like a watchdog 2618 prio => 6, # keep it lowest so it acts like a watchdog
2623 cb => Coro::unblock_sub { 2619 cb => sub {
2620 $TICK_WATCHER->is_active or cf::cleanup "mainloop frozen but runtime active", 1;
2621
2622 Coro::async_pool {
2624 write_runtime 2623 write_runtime
2625 or warn "ERROR: unable to write runtime file: $!"; 2624 or warn "ERROR: unable to write runtime file: $!";
2625 };
2626 }, 2626 },
2627); 2627);
2628 2628
2629END { cf::emergency_save } 2629END { cf::emergency_save }
2630 2630

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines