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.312 by root, Sat Jul 21 18:01:26 2007 UTC vs.
Revision 1.315 by root, Mon Jul 23 17:53:55 2007 UTC

320 my $guard = Coro::guard { 320 my $guard = Coro::guard {
321 $TICK_WATCHER->start; 321 $TICK_WATCHER->start;
322 }; 322 };
323 $TICK_WATCHER->stop; 323 $TICK_WATCHER->stop;
324 $guard 324 $guard
325}
326
327=item cf::get_slot $time[, $priority[, $name]]
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
333The optional C<$name> can be used to identify the job to run. It might be
334used for statistical purposes and should identify the same time-class.
335
336Useful for short background jobs.
337
338=cut
339
340our @SLOT_QUEUE;
341our $SLOT_QUEUE;
342
343$SLOT_QUEUE->cancel if $SLOT_QUEUE;
344$SLOT_QUEUE = Coro::async {
345 my $signal = new Coro::Signal;
346
347 while () {
348 next_job:
349 my $avail = cf::till_tick;
350 if ($avail > 0.01) {
351 for (0 .. $#SLOT_QUEUE) {
352 if ($SLOT_QUEUE[$_][0] < $avail) {
353 my $job = splice @SLOT_QUEUE, $_, 1, ();
354 $job->[2]->send;
355 Coro::cede;
356 goto next_job;
357 }
358 }
359 }
360
361 if (@SLOT_QUEUE) {
362 # we do not use wait_For_tick() as it returns immediately when tick is inactive
363 push @cf::WAIT_FOR_TICK, $signal;
364 $signal->wait;
365 } else {
366 Coro::schedule;
367 }
368 }
369};
370
371sub get_slot($;$$) {
372 my ($time, $pri, $name) = @_;
373
374 $time = $TICK * .6 if $time > $TICK * .6;
375 my $sig = new Coro::Signal;
376
377 push @SLOT_QUEUE, [$time, $pri, $sig, $name];
378 @SLOT_QUEUE = sort { $b->[1] <=> $a->[1] } @SLOT_QUEUE;
379 $SLOT_QUEUE->ready;
380 $sig->wait;
325} 381}
326 382
327=item cf::async { BLOCK } 383=item cf::async { BLOCK }
328 384
329Currently the same as Coro::async_pool, meaning you cannot use 385Currently the same as Coro::async_pool, meaning you cannot use
2450sub cf::client::send_msg { 2506sub cf::client::send_msg {
2451 my ($self, $channel, $msg, $color, @extra) = @_; 2507 my ($self, $channel, $msg, $color, @extra) = @_;
2452 2508
2453 $msg = $self->pl->expand_cfpod ($msg); 2509 $msg = $self->pl->expand_cfpod ($msg);
2454 2510
2455 return unless @extra || length $msg;
2456
2457 $color &= ~cf::NDI_UNIQUE; # just in case... 2511 $color &= ~cf::NDI_UNIQUE; # just in case...
2458 2512
2459 if (ref $channel) { 2513 if (ref $channel) {
2460 # send meta info to client, if not yet sent 2514 # send meta info to client, if not yet sent
2461 unless (exists $self->{channel}{$channel->{id}}) { 2515 unless (exists $self->{channel}{$channel->{id}}) {
2463 $self->ext_event (channel_info => %$channel); 2517 $self->ext_event (channel_info => %$channel);
2464 } 2518 }
2465 2519
2466 $channel = $channel->{id}; 2520 $channel = $channel->{id};
2467 } 2521 }
2522
2523 return unless @extra || length $msg;
2468 2524
2469 if ($self->can_msg) { 2525 if ($self->can_msg) {
2470 $self->send_packet ("msg " . $self->{json_coder}->encode ([$color, $channel, $msg, @extra])); 2526 $self->send_packet ("msg " . $self->{json_coder}->encode ([$color, $channel, $msg, @extra]));
2471 } else { 2527 } else {
2472 # replace some tags by gcfclient-compatible ones 2528 # replace some tags by gcfclient-compatible ones

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines