--- deliantra/server/lib/cf.pm 2007/01/04 16:19:32 1.133 +++ deliantra/server/lib/cf.pm 2007/01/05 10:23:05 1.137 @@ -181,28 +181,6 @@ JSON::Syck::Dump $_[0] } -=item my $guard = cf::guard { BLOCK } - -Run the given callback when the guard object gets destroyed (useful for -coroutine cancellations). - -You can call C<< ->cancel >> on the guard object to stop the block from -being executed. - -=cut - -sub guard(&) { - bless \(my $cb = $_[0]), cf::guard::; -} - -sub cf::guard::cancel { - ${$_[0]} = sub { }; -} - -sub cf::guard::DESTROY { - ${$_[0]}->(); -} - =item cf::lock_wait $string Wait until the given lock is available. See cf::lock_acquire. @@ -210,7 +188,7 @@ =item my $lock = cf::lock_acquire $string Wait until the given lock is available and then acquires it and returns -a guard object. If the guard object gets destroyed (goes out of scope, +a Coro::guard object. If the guard object gets destroyed (goes out of scope, for example when the coroutine gets canceled), the lock is automatically returned. @@ -239,7 +217,7 @@ $LOCK{$key} = []; - cf::guard { + Coro::guard { # wake up all waiters, to be on the safe side $_->ready for @{ delete $LOCK{$key} }; } @@ -264,7 +242,7 @@ sub freeze_mainloop { return unless $TICK_WATCHER->is_active; - my $guard = guard { $TICK_WATCHER->start }; + my $guard = Coro::guard { $TICK_WATCHER->start }; $TICK_WATCHER->stop; $guard } @@ -1186,6 +1164,9 @@ my $map = cf::map::new or return; + # for better error messages only, will be overwritten + $map->path ($path); + $map->load_header ($path) or return; @@ -1211,6 +1192,8 @@ # do it the slow way my $map = try_load_header $path->save_path; + Coro::cede; + if ($map) { $map->last_access ((delete $map->{last_access}) || $cf::RUNTIME); #d# @@ -1239,6 +1222,8 @@ $map->{path} = $path; $map->{last_save} = $cf::RUNTIME; + Coro::cede; + if ($map->should_reset) { $map->reset; undef $guard; @@ -1275,6 +1260,8 @@ } } + Coro::cede; + # now do the right thing for maps $self->link_multipart_objects; @@ -1291,6 +1278,8 @@ $self->activate; } + Coro::cede; + $self->in_memory (cf::MAP_IN_MEMORY); } @@ -1309,6 +1298,8 @@ sub save { my ($self) = @_; + my $lock = cf::lock_acquire "map_data:" . $self->path; + $self->{last_save} = $cf::RUNTIME; return unless $self->dirty; @@ -1336,6 +1327,8 @@ # save first because save cedes $self->save; + my $lock = cf::lock_acquire "map_data:" . $self->path; + return if $self->players; return if $self->in_memory != cf::MAP_IN_MEMORY; return if $self->{deny_save}; @@ -1387,6 +1380,8 @@ sub reset { my ($self) = @_; + my $lock = cf::lock_acquire "map_data:" . $self->path; + return if $self->players; return if $self->{path}{user_rel};#d# @@ -1572,11 +1567,11 @@ }, ); -=item $player_object->goto_map ($path, $x, $y) +=item $player_object->goto ($path, $x, $y) =cut -sub cf::object::player::goto_map { +sub cf::object::player::goto { my ($self, $path, $x, $y) = @_; $self->enter_link; @@ -1660,7 +1655,7 @@ if $exit->slaying eq "/!"; my $path = new cf::path $exit->slaying, $exit->map && $exit->map->path; - $self->goto_map ($path, $exit->stats->hp, $exit->stats->sp); + $self->goto ($path, $exit->stats->hp, $exit->stats->sp); 1; }) {