--- deliantra/server/lib/cf.pm 2010/04/29 07:59:17 1.533 +++ deliantra/server/lib/cf.pm 2010/04/29 08:13:51 1.534 @@ -520,13 +520,13 @@ sub sync_job(&) { my ($job) = @_; - if ($Coro::current == $Coro::main) { + if (in_main) { my $time = AE::time; # this is the main coro, too bad, we have to block # till the operation succeeds, freezing the server :/ - LOG llevError, Carp::longmess "sync job";#d# + #LOG llevError, Carp::longmess "sync job";#d# my $freeze_guard = freeze_mainloop; @@ -659,6 +659,9 @@ =cut sub db_table($) { + cf::error "db_get called from main context" + if $Coro::current == $Coro::main; + my ($name) = @_; my $db = BDB::db_create $DB_ENV; @@ -678,20 +681,19 @@ our $DB; sub db_init { - cf::sync_job { - $DB ||= db_table "db"; - }; + $DB ||= db_table "db"; } sub db_get($$) { my $key = "$_[0]/$_[1]"; - cf::sync_job { - BDB::db_get $DB, undef, $key, my $data; + cf::error "db_get called from main context" + if $Coro::current == $Coro::main; - $! ? () - : $data - } + BDB::db_get $DB, undef, $key, my $data; + + $! ? () + : $data } sub db_put($$$) { @@ -2192,16 +2194,19 @@ sub find_sync { my ($path, $origin) = @_; - cf::sync_job { find $path, $origin } + return cf::LOG cf::llevError | cf::logBacktrace, "do_find_sync" + if $Coro::current == $Coro::main; + + find $path, $origin } sub do_load_sync { my ($map) = @_; - cf::LOG cf::llevDebug | cf::logBacktrace, "do_load_sync" + return cf::LOG cf::llevError | cf::logBacktrace, "do_load_sync" if $Coro::current == $Coro::main; - cf::sync_job { $map->load }; + $map->load; } our %MAP_PREFETCH; @@ -3749,12 +3754,12 @@ info "emergency_perl_save: enter\n"; - cf::sync_job { - # this is a trade-off: we want to be very quick here, so - # save all maps without fsync, and later call a global sync - # (which in turn might be very very slow) - local $USE_FSYNC = 0; + # this is a trade-off: we want to be very quick here, so + # save all maps without fsync, and later call a global sync + # (which in turn might be very very slow) + local $USE_FSYNC = 0; + cf::sync_job { # use a peculiar iteration method to avoid tripping on perl # refcount bugs in for. also avoids problems with players # and maps saved/destroyed asynchronously. @@ -4058,22 +4063,20 @@ $DB_ENV->set_timeout (30, BDB::SET_TXN_TIMEOUT); $DB_ENV->set_timeout (30, BDB::SET_LOCK_TIMEOUT); - (Coro::async { # async to keep sync_job from complaining - cf::sync_job { - eval { - BDB::db_env_open - $DB_ENV, - $BDBDIR, - BDB::INIT_LOCK | BDB::INIT_LOG | BDB::INIT_MPOOL | BDB::INIT_TXN - | BDB::RECOVER | BDB::REGISTER | BDB::USE_ENVIRON | BDB::CREATE, - 0666; - - cf::cleanup "db_env_open($BDBDIR): $!" if $!; - }; + cf::sync_job { + eval { + BDB::db_env_open + $DB_ENV, + $BDBDIR, + BDB::INIT_LOCK | BDB::INIT_LOG | BDB::INIT_MPOOL | BDB::INIT_TXN + | BDB::RECOVER | BDB::REGISTER | BDB::USE_ENVIRON | BDB::CREATE, + 0666; - cf::cleanup "db_env_open(db): $@" if $@; + cf::cleanup "db_env_open($BDBDIR): $!" if $!; }; - })->join; + + cf::cleanup "db_env_open(db): $@" if $@; + }; } $BDB_DEADLOCK_WATCHER = EV::periodic 0, 3, 0, sub {