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.412 by root, Wed Apr 2 11:13:55 2008 UTC vs.
Revision 1.416 by root, Fri Apr 11 13:59:06 2008 UTC

25use strict; 25use strict;
26 26
27use Symbol; 27use Symbol;
28use List::Util; 28use List::Util;
29use Socket; 29use Socket;
30use EV 1.86; 30use EV 3.2;
31use Opcode; 31use Opcode;
32use Safe; 32use Safe;
33use Safe::Hole; 33use Safe::Hole;
34use Storable (); 34use Storable ();
35 35
36use Coro 4.32 (); 36use Coro 4.50 ();
37use Coro::State; 37use Coro::State;
38use Coro::Handle; 38use Coro::Handle;
39use Coro::EV; 39use Coro::EV;
40use Coro::Timer; 40use Coro::Timer;
41use Coro::Signal; 41use Coro::Signal;
547 reset_signals; 547 reset_signals;
548 &$cb 548 &$cb
549 }, @args; 549 }, @args;
550 550
551 wantarray ? @res : $res[-1] 551 wantarray ? @res : $res[-1]
552}
553
554=item $coin = coin_from_name $name
555
556=cut
557
558our %coin_alias = (
559 "silver" => "silvercoin",
560 "silvercoin" => "silvercoin",
561 "silvercoins" => "silvercoin",
562 "gold" => "goldcoin",
563 "goldcoin" => "goldcoin",
564 "goldcoins" => "goldcoin",
565 "platinum" => "platinacoin",
566 "platinumcoin" => "platinacoin",
567 "platinumcoins" => "platinacoin",
568 "platina" => "platinacoin",
569 "platinacoin" => "platinacoin",
570 "platinacoins" => "platinacoin",
571 "royalty" => "royalty",
572 "royalties" => "royalty",
573);
574
575sub coin_from_name($) {
576 $coin_alias{$_[0]}
577 ? cf::arch::find $coin_alias{$_[0]}
578 : undef
552} 579}
553 580
554=item $value = cf::db_get $family => $key 581=item $value = cf::db_get $family => $key
555 582
556Returns a single value from the environment database. 583Returns a single value from the environment database.
2349 ? normalise $_ 2376 ? normalise $_
2350 : () 2377 : ()
2351 } @{ aio_readdir $UNIQUEDIR or [] } 2378 } @{ aio_readdir $UNIQUEDIR or [] }
2352 ] 2379 ]
2353} 2380}
2354
2355package cf;
2356 2381
2357=back 2382=back
2358 2383
2359=head3 cf::object 2384=head3 cf::object
2360 2385
3362 reload_config; 3387 reload_config;
3363 db_init; 3388 db_init;
3364 load_extensions; 3389 load_extensions;
3365 3390
3366 $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority 3391 $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority
3367 evthread_start; 3392 evthread_start IO::AIO::poll_fileno;
3368 EV::loop; 3393 EV::loop;
3369} 3394}
3370 3395
3371############################################################################# 3396#############################################################################
3372# initialisation and cleanup 3397# initialisation and cleanup
3415 and return; 3440 and return;
3416 3441
3417 warn "runtime file written.\n"; 3442 warn "runtime file written.\n";
3418 3443
3419 1 3444 1
3445}
3446
3447our $uuid_lock;
3448our $uuid_skip;
3449
3450sub write_uuid_sync($) {
3451 $uuid_skip ||= $_[0];
3452
3453 return if $uuid_lock;
3454 local $uuid_lock = 1;
3455
3456 my $uuid = "$LOCALDIR/uuid";
3457
3458 my $fh = aio_open "$uuid~", O_WRONLY | O_CREAT, 0644
3459 or return;
3460
3461 my $value = uuid_str $uuid_skip + uuid_seq uuid_cur;
3462 $uuid_skip = 0;
3463
3464 (aio_write $fh, 0, (length $value), $value, 0) <= 0
3465 and return;
3466
3467 # always fsync - this file is important
3468 aio_fsync $fh
3469 and return;
3470
3471 close $fh
3472 or return;
3473
3474 aio_rename "$uuid~", $uuid
3475 and return;
3476
3477 warn "uuid file written ($value).\n";
3478
3479 1
3480
3481}
3482
3483sub write_uuid($$) {
3484 my ($skip, $sync) = @_;
3485
3486 $sync ? write_uuid_sync $skip
3487 : async { write_uuid_sync $skip };
3420} 3488}
3421 3489
3422sub emergency_save() { 3490sub emergency_save() {
3423 my $freeze_guard = cf::freeze_mainloop; 3491 my $freeze_guard = cf::freeze_mainloop;
3424 3492
3446 warn "end emergency map save\n"; 3514 warn "end emergency map save\n";
3447 3515
3448 warn "begin emergency database checkpoint\n"; 3516 warn "begin emergency database checkpoint\n";
3449 BDB::db_env_txn_checkpoint $DB_ENV; 3517 BDB::db_env_txn_checkpoint $DB_ENV;
3450 warn "end emergency database checkpoint\n"; 3518 warn "end emergency database checkpoint\n";
3519
3520 warn "begin write uuid\n";
3521 write_uuid_sync 1;
3522 warn "end write uuid\n";
3451 }; 3523 };
3452 3524
3453 warn "leave emergency perl save\n"; 3525 warn "leave emergency perl save\n";
3454} 3526}
3455 3527

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines