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.213 by root, Tue Feb 13 20:01:04 2007 UTC vs.
Revision 1.215 by root, Thu Feb 15 03:19:02 2007 UTC

49our $LIBDIR = datadir . "/ext"; 49our $LIBDIR = datadir . "/ext";
50 50
51our $TICK = MAX_TIME * 1e-6; 51our $TICK = MAX_TIME * 1e-6;
52our $TICK_WATCHER; 52our $TICK_WATCHER;
53our $AIO_POLL_WATCHER; 53our $AIO_POLL_WATCHER;
54our $WRITE_RUNTIME_WATCHER; 54our $NEXT_RUNTIME_WRITE; # when should the runtime file be written
55our $NEXT_TICK; 55our $NEXT_TICK;
56our $NOW; 56our $NOW;
57our $USE_FSYNC = 1; # use fsync to write maps - default off 57our $USE_FSYNC = 1; # use fsync to write maps - default off
58 58
59our $BDB_POLL_WATCHER; 59our $BDB_POLL_WATCHER;
273sub freeze_mainloop { 273sub freeze_mainloop {
274 return unless $TICK_WATCHER->is_active; 274 return unless $TICK_WATCHER->is_active;
275 275
276 my $guard = Coro::guard { 276 my $guard = Coro::guard {
277 $TICK_WATCHER->start; 277 $TICK_WATCHER->start;
278 $WRITE_RUNTIME_WATCHER->start;
279 }; 278 };
280 $WRITE_RUNTIME_WATCHER->stop;
281 $TICK_WATCHER->stop; 279 $TICK_WATCHER->stop;
282 $guard 280 $guard
283} 281}
284 282
285=item cf::async { BLOCK } 283=item cf::async { BLOCK }
1820 $map->load; 1818 $map->load;
1821 $map->load_diag; 1819 $map->load_diag;
1822 1820
1823 return unless $self->contr->active; 1821 return unless $self->contr->active;
1824 $self->activate_recursive; 1822 $self->activate_recursive;
1823
1824 local $self->{_prev_pos} = $link_pos; # ugly hack for rent.ext
1825 $self->enter_map ($map, $x, $y); 1825 $self->enter_map ($map, $x, $y);
1826} 1826}
1827 1827
1828cf::player->attach ( 1828cf::player->attach (
1829 on_logout => sub { 1829 on_logout => sub {
1842 # try to abort aborted map switching on player login :) 1842 # try to abort aborted map switching on player login :)
1843 # should happen only on crashes 1843 # should happen only on crashes
1844 if ($pl->ob->{_link_pos}) { 1844 if ($pl->ob->{_link_pos}) {
1845 $pl->ob->enter_link; 1845 $pl->ob->enter_link;
1846 (async { 1846 (async {
1847 # we need this sleep as the login has a concurrent enter_exit running
1848 # and this sleep increases chances of the player not ending up in scorn
1849 $pl->ob->reply (undef, 1847 $pl->ob->reply (undef,
1850 "There was an internal problem at your last logout, " 1848 "There was an internal problem at your last logout, "
1851 . "the server will try to bring you to your intended destination in a second.", 1849 . "the server will try to bring you to your intended destination in a second.",
1852 cf::NDI_RED); 1850 cf::NDI_RED);
1851 # we need this sleep as the login has a concurrent enter_exit running
1852 # and this sleep increases chances of the player not ending up in scorn
1853 Coro::Timer::sleep 1; 1853 Coro::Timer::sleep 1;
1854 $pl->ob->leave_link; 1854 $pl->ob->leave_link;
1855 })->prio (2); 1855 })->prio (2);
1856 } 1856 }
1857 }, 1857 },
2300 cfg_load; 2300 cfg_load;
2301 db_init; 2301 db_init;
2302 load_extensions; 2302 load_extensions;
2303 2303
2304 $TICK_WATCHER->start; 2304 $TICK_WATCHER->start;
2305 $WRITE_RUNTIME_WATCHER->start;
2306 Event::loop; 2305 Event::loop;
2307} 2306}
2308 2307
2309############################################################################# 2308#############################################################################
2310# initialisation and cleanup 2309# initialisation and cleanup
2374 warn "reloading..."; 2373 warn "reloading...";
2375 2374
2376 warn "entering sync_job"; 2375 warn "entering sync_job";
2377 2376
2378 cf::sync_job { 2377 cf::sync_job {
2379 cf::write_runtime; 2378 cf::write_runtime; # external watchdog should not bark
2380 cf::emergency_save; 2379 cf::emergency_save;
2381 cf::write_runtime; 2380 cf::write_runtime; # external watchdog should not bark
2382 2381
2383 warn "syncing database to disk"; 2382 warn "syncing database to disk";
2384 BDB::db_env_txn_checkpoint $DB_ENV; 2383 BDB::db_env_txn_checkpoint $DB_ENV;
2385 2384
2386 # 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
2527 $NOW = Event::time; 2526 $NOW = Event::time;
2528 2527
2529 cf::server_tick; # one server iteration 2528 cf::server_tick; # one server iteration
2530 $RUNTIME += $TICK; 2529 $RUNTIME += $TICK;
2531 $NEXT_TICK += $TICK; 2530 $NEXT_TICK += $TICK;
2531
2532 if ($NOW >= $NEXT_RUNTIME_WRITE) {
2533 $NEXT_RUNTIME_WRITE = $NOW + 10;
2534 Coro::async_pool {
2535 write_runtime
2536 or warn "ERROR: unable to write runtime file: $!";
2537 };
2538 }
2539
2532 2540
2533 $WAIT_FOR_TICK->broadcast; 2541 $WAIT_FOR_TICK->broadcast;
2534 $WAIT_FOR_TICK_ONE->send if $WAIT_FOR_TICK_ONE->awaited; 2542 $WAIT_FOR_TICK_ONE->send if $WAIT_FOR_TICK_ONE->awaited;
2535 2543
2536# my $AFTER = Event::time; 2544# my $AFTER = Event::time;
2599 2607
2600 undef $Coro::AIO::WATCHER; 2608 undef $Coro::AIO::WATCHER;
2601 IO::AIO::max_poll_time $TICK * 0.1; 2609 IO::AIO::max_poll_time $TICK * 0.1;
2602 $AIO_POLL_WATCHER = Event->io ( 2610 $AIO_POLL_WATCHER = Event->io (
2603 reentrant => 0, 2611 reentrant => 0,
2612 data => WF_AUTOCANCEL,
2604 fd => IO::AIO::poll_fileno, 2613 fd => IO::AIO::poll_fileno,
2605 poll => 'r', 2614 poll => 'r',
2606 prio => 6, 2615 prio => 6,
2607 data => WF_AUTOCANCEL,
2608 cb => \&IO::AIO::poll_cb, 2616 cb => \&IO::AIO::poll_cb,
2609 ); 2617 );
2610} 2618}
2611 2619
2612$WRITE_RUNTIME_WATCHER = Event->timer (
2613 reentrant => 0,
2614 data => WF_AUTOCANCEL,
2615 parked => 1,
2616 after => 1,
2617 interval => 10,
2618 prio => 6, # keep it lowest so it acts like a watchdog
2619 cb => sub {
2620 $TICK_WATCHER->is_active or cf::cleanup "mainloop frozen but runtime active", 1;
2621
2622 Coro::async_pool {
2623 write_runtime
2624 or warn "ERROR: unable to write runtime file: $!";
2625 };
2626 },
2627);
2628
2629END { cf::emergency_save } 2620END { cf::emergency_save }
2630 2621
26311 26221
2632 2623

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines