… | |
… | |
8 | use Storable; |
8 | use Storable; |
9 | use Opcode; |
9 | use Opcode; |
10 | use Safe; |
10 | use Safe; |
11 | use Safe::Hole; |
11 | use Safe::Hole; |
12 | |
12 | |
13 | use Coro 3.3 (); |
13 | use Coro 3.4 (); |
14 | use Coro::Event; |
14 | use Coro::Event; |
15 | use Coro::Timer; |
15 | use Coro::Timer; |
16 | use Coro::Signal; |
16 | use Coro::Signal; |
17 | use Coro::Semaphore; |
17 | use Coro::Semaphore; |
18 | use Coro::AIO; |
18 | use Coro::AIO; |
… | |
… | |
1535 | my ($self) = @_; |
1535 | my ($self) = @_; |
1536 | |
1536 | |
1537 | $self->reset_at <= $cf::RUNTIME |
1537 | $self->reset_at <= $cf::RUNTIME |
1538 | } |
1538 | } |
1539 | |
1539 | |
1540 | sub rename { |
|
|
1541 | my ($self, $new_path) = @_; |
|
|
1542 | |
|
|
1543 | normalise $new_path; |
|
|
1544 | |
|
|
1545 | $self->unlink_save; |
|
|
1546 | |
|
|
1547 | delete $cf::MAP{$self->path}; |
|
|
1548 | $self->{path} = $new_path; $self->path ($self->{path}); |
|
|
1549 | $cf::MAP{$self->path} = $self; |
|
|
1550 | |
|
|
1551 | $self->save; |
|
|
1552 | } |
|
|
1553 | |
|
|
1554 | sub reset { |
1540 | sub reset { |
1555 | my ($self) = @_; |
1541 | my ($self) = @_; |
1556 | |
1542 | |
1557 | my $lock = cf::lock_acquire "map_data:$self->{path}"; |
1543 | my $lock = cf::lock_acquire "map_data:$self->{path}"; |
1558 | |
1544 | |
… | |
… | |
1575 | my $nuke_counter = "aaaa"; |
1561 | my $nuke_counter = "aaaa"; |
1576 | |
1562 | |
1577 | sub nuke { |
1563 | sub nuke { |
1578 | my ($self) = @_; |
1564 | my ($self) = @_; |
1579 | |
1565 | |
|
|
1566 | delete $cf::MAP{$self->path}; |
|
|
1567 | |
|
|
1568 | $self->unlink_save; |
|
|
1569 | |
|
|
1570 | bless $self, "cf::map"; |
|
|
1571 | delete $self->{deny_reset}; |
1580 | $self->{deny_save} = 1; |
1572 | $self->{deny_save} = 1; |
1581 | $self->reset_timeout (1); |
1573 | $self->reset_timeout (1); |
1582 | $self->rename ("{nuke}/" . ($nuke_counter++)); |
1574 | $self->path ($self->{path} = "{nuke}/" . ($nuke_counter++)); |
|
|
1575 | |
|
|
1576 | $cf::MAP{$self->path} = $self; |
|
|
1577 | |
1583 | $self->reset; # polite request, might not happen |
1578 | $self->reset; # polite request, might not happen |
1584 | } |
1579 | } |
1585 | |
1580 | |
1586 | =item cf::map::unique_maps |
1581 | =item cf::map::unique_maps |
1587 | |
1582 | |
… | |
… | |
2233 | |
2228 | |
2234 | sub main { |
2229 | sub main { |
2235 | # we must not ever block the main coroutine |
2230 | # we must not ever block the main coroutine |
2236 | local $Coro::idle = sub { |
2231 | local $Coro::idle = sub { |
2237 | Carp::cluck "FATAL: Coro::idle was called, major BUG, use cf::sync_job!\n";#d# |
2232 | Carp::cluck "FATAL: Coro::idle was called, major BUG, use cf::sync_job!\n";#d# |
|
|
2233 | (async { |
2238 | async { Event::one_event }; |
2234 | Event::one_event; |
|
|
2235 | })->prio (Coro::PRIO_MAX); |
2239 | }; |
2236 | }; |
2240 | |
2237 | |
2241 | cfg_load; |
2238 | cfg_load; |
2242 | db_load; |
2239 | db_load; |
2243 | load_extensions; |
2240 | load_extensions; |
… | |
… | |
2391 | } |
2388 | } |
2392 | |
2389 | |
2393 | warn "reloaded"; |
2390 | warn "reloaded"; |
2394 | }; |
2391 | }; |
2395 | |
2392 | |
|
|
2393 | our $RELOAD_WATCHER; # used only during reload |
|
|
2394 | |
2396 | register_command "reload" => sub { |
2395 | register_command "reload" => sub { |
2397 | my ($who, $arg) = @_; |
2396 | my ($who, $arg) = @_; |
2398 | |
2397 | |
2399 | if ($who->flag (FLAG_WIZ)) { |
2398 | if ($who->flag (FLAG_WIZ)) { |
2400 | $who->message ("start of reload."); |
2399 | $who->message ("reloading server."); |
|
|
2400 | |
|
|
2401 | # doing reload synchronously and two reloads happen back-to-back, |
|
|
2402 | # coro crashes during coro_state_free->destroy here. |
|
|
2403 | |
|
|
2404 | $RELOAD_WATCHER ||= Event->timer (after => 0, data => WF_AUTOCANCEL, cb => sub { |
2401 | reload; |
2405 | reload; |
2402 | $who->message ("end of reload."); |
2406 | undef $RELOAD_WATCHER; |
|
|
2407 | }); |
2403 | } |
2408 | } |
2404 | }; |
2409 | }; |
2405 | |
2410 | |
2406 | unshift @INC, $LIBDIR; |
2411 | unshift @INC, $LIBDIR; |
2407 | |
2412 | |