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.357 by root, Tue Sep 4 08:42:58 2007 UTC vs.
Revision 1.358 by root, Fri Sep 7 18:10:52 2007 UTC

285Return true if the lock is currently active, i.e. somebody has locked it. 285Return true if the lock is currently active, i.e. somebody has locked it.
286 286
287=cut 287=cut
288 288
289our %LOCK; 289our %LOCK;
290our %LOCKER;#d#
290 291
291sub lock_wait($) { 292sub lock_wait($) {
292 my ($key) = @_; 293 my ($key) = @_;
294
295 if ($LOCKER{$key} == $Coro::current) {#d#
296 Carp::cluck "lock_wait($key) for already-acquired lock";#d#
297 return;#d#
298 }#d#
293 299
294 # wait for lock, if any 300 # wait for lock, if any
295 while ($LOCK{$key}) { 301 while ($LOCK{$key}) {
296 push @{ $LOCK{$key} }, $Coro::current; 302 push @{ $LOCK{$key} }, $Coro::current;
297 Coro::schedule; 303 Coro::schedule;
303 309
304 # wait, to be sure we are not locked 310 # wait, to be sure we are not locked
305 lock_wait $key; 311 lock_wait $key;
306 312
307 $LOCK{$key} = []; 313 $LOCK{$key} = [];
314 $LOCKER{$key} = $Coro::current;#d#
308 315
309 Coro::guard { 316 Coro::guard {
317 delete $LOCKER{$key};#d#
310 # wake up all waiters, to be on the safe side 318 # wake up all waiters, to be on the safe side
311 $_->ready for @{ delete $LOCK{$key} }; 319 $_->ready for @{ delete $LOCK{$key} };
312 } 320 }
313} 321}
314 322
1841sub find { 1849sub find {
1842 my ($path, $origin) = @_; 1850 my ($path, $origin) = @_;
1843 1851
1844 $path = normalise $path, $origin && $origin->path; 1852 $path = normalise $path, $origin && $origin->path;
1845 1853
1854 cf::lock_wait "map_data:$path";#d#remove
1846 cf::lock_wait "map_find:$path"; 1855 cf::lock_wait "map_find:$path";
1847 1856
1848 $cf::MAP{$path} || do { 1857 $cf::MAP{$path} || do {
1849 my $guard = cf::lock_acquire "map_find:$path"; 1858 my $guard1 = cf::lock_acquire "map_find:$path";
1859 my $guard2 = cf::lock_acquire "map_data:$path"; # just for the fun of it
1860
1850 my $map = new_from_path cf::map $path 1861 my $map = new_from_path cf::map $path
1851 or return; 1862 or return;
1852 1863
1853 $map->{last_save} = $cf::RUNTIME; 1864 $map->{last_save} = $cf::RUNTIME;
1854 1865
1856 or return; 1867 or return;
1857 1868
1858 if ($map->should_reset) {#d#TODO# disabled, crashy (locking issue?) 1869 if ($map->should_reset) {#d#TODO# disabled, crashy (locking issue?)
1859 # doing this can freeze the server in a sync job, obviously 1870 # doing this can freeze the server in a sync job, obviously
1860 #$cf::WAIT_FOR_TICK->wait; 1871 #$cf::WAIT_FOR_TICK->wait;
1872 undef $guard1;
1873 undef $guard2;
1861 $map->reset; 1874 $map->reset;
1862 undef $guard;
1863 return find $path; 1875 return find $path;
1864 } 1876 }
1865 1877
1866 $cf::MAP{$path} = $map 1878 $cf::MAP{$path} = $map
1867 } 1879 }
2061 2073
2062 return if $self->players; 2074 return if $self->players;
2063 return if $self->in_memory != cf::MAP_IN_MEMORY; 2075 return if $self->in_memory != cf::MAP_IN_MEMORY;
2064 return if $self->{deny_save}; 2076 return if $self->{deny_save};
2065 2077
2078 $self->deactivate;
2066 $self->clear; 2079 $self->clear;
2067 $self->in_memory (cf::MAP_SWAPPED); 2080 $self->in_memory (cf::MAP_SWAPPED);
2068} 2081}
2069 2082
2070sub reset_at { 2083sub reset_at {
2104 if $uniq; 2117 if $uniq;
2105 } 2118 }
2106 2119
2107 delete $cf::MAP{$self->path}; 2120 delete $cf::MAP{$self->path};
2108 2121
2122 $self->deactivate;
2109 $self->clear; 2123 $self->clear;
2110 2124
2111 $_->clear_links_to ($self) for values %cf::MAP; 2125 $_->clear_links_to ($self) for values %cf::MAP;
2112 2126
2113 $self->unlink_save; 2127 $self->unlink_save;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines