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.311 by root, Fri Jul 20 16:11:10 2007 UTC vs.
Revision 1.314 by root, Mon Jul 23 16:53:15 2007 UTC

322 }; 322 };
323 $TICK_WATCHER->stop; 323 $TICK_WATCHER->stop;
324 $guard 324 $guard
325} 325}
326 326
327=item cf::get_slot $time[, $priority]
328
329Allocate $time seconds of blocking CPU time at priority C<$priority>:
330This call blocks and returns only when you have at least C<$time> seconds
331of cpu time till the next tick. The slot is only valid till the next cede.
332
333Useful for short background jobs.
334
335=cut
336
337our @SLOT_QUEUE;
338our $SLOT_QUEUE;
339
340$SLOT_QUEUE->cancel if $SLOT_QUEUE;
341$SLOT_QUEUE = Coro::async {
342 my $signal = new Coro::Signal;
343
344 while () {
345 next_job:
346 my $avail = cf::till_tick;
347 if ($avail > 0.01) {
348 for (0 .. $#SLOT_QUEUE) {
349 if ($SLOT_QUEUE[$_][0] < $avail) {
350 my $job = splice @SLOT_QUEUE, $_, 1, ();
351 $job->[2]->send;
352 Coro::cede;
353 goto next_job;
354 }
355 }
356 }
357
358 if (@SLOT_QUEUE) {
359 # we do not use wait_For_tick() as it returns immediately when tick is inactive
360 push @cf::WAIT_FOR_TICK, $signal;
361 $signal->wait;
362 } else {
363 Coro::schedule;
364 }
365 }
366};
367
368sub get_slot($;$) {
369 my ($time, $pri) = @_;
370
371 push @SLOT_QUEUE, [$time, $pri, my $sig = new Coro::Signal];
372 @SLOT_QUEUE = sort { $b->[1] <=> $a->[1] } @SLOT_QUEUE;
373 $SLOT_QUEUE->ready;
374 $sig->wait;
375}
376
327=item cf::async { BLOCK } 377=item cf::async { BLOCK }
328 378
329Currently the same as Coro::async_pool, meaning you cannot use 379Currently the same as Coro::async_pool, meaning you cannot use
330C<on_destroy>, C<join> or other gimmicks on these coroutines. The only 380C<on_destroy>, C<join> or other gimmicks on these coroutines. The only
331thing you are allowed to do is call C<prio> on it. 381thing you are allowed to do is call C<prio> on it.
918 968
919=cut 969=cut
920 970
921############################################################################# 971#############################################################################
922# object support 972# object support
973#
974
975sub _can_merge {
976 my ($ob1, $ob2) = @_;
977
978 local $Storable::canonical = 1;
979 my $fob1 = Storable::freeze $ob1;
980 my $fob2 = Storable::freeze $ob2;
981
982 $fob1 eq $fob2
983}
923 984
924sub reattach { 985sub reattach {
925 # basically do the same as instantiate, without calling instantiate 986 # basically do the same as instantiate, without calling instantiate
926 my ($obj) = @_; 987 my ($obj) = @_;
927 988
2439sub cf::client::send_msg { 2500sub cf::client::send_msg {
2440 my ($self, $channel, $msg, $color, @extra) = @_; 2501 my ($self, $channel, $msg, $color, @extra) = @_;
2441 2502
2442 $msg = $self->pl->expand_cfpod ($msg); 2503 $msg = $self->pl->expand_cfpod ($msg);
2443 2504
2444 return unless @extra || length $msg;
2445
2446 $color &= ~cf::NDI_UNIQUE; # just in case... 2505 $color &= ~cf::NDI_UNIQUE; # just in case...
2447 2506
2448 if (ref $channel) { 2507 if (ref $channel) {
2449 # send meta info to client, if not yet sent 2508 # send meta info to client, if not yet sent
2450 unless (exists $self->{channel}{$channel->{id}}) { 2509 unless (exists $self->{channel}{$channel->{id}}) {
2452 $self->ext_event (channel_info => %$channel); 2511 $self->ext_event (channel_info => %$channel);
2453 } 2512 }
2454 2513
2455 $channel = $channel->{id}; 2514 $channel = $channel->{id};
2456 } 2515 }
2516
2517 return unless @extra || length $msg;
2457 2518
2458 if ($self->can_msg) { 2519 if ($self->can_msg) {
2459 $self->send_packet ("msg " . $self->{json_coder}->encode ([$color, $channel, $msg, @extra])); 2520 $self->send_packet ("msg " . $self->{json_coder}->encode ([$color, $channel, $msg, @extra]));
2460 } else { 2521 } else {
2461 # replace some tags by gcfclient-compatible ones 2522 # replace some tags by gcfclient-compatible ones

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines