… | |
… | |
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] |
327 | =item cf::get_slot $time[, $priority[, $name]] |
328 | |
328 | |
329 | Allocate $time seconds of blocking CPU time at priority C<$priority>: |
329 | Allocate $time seconds of blocking CPU time at priority C<$priority>: |
330 | This call blocks and returns only when you have at least C<$time> seconds |
330 | This call blocks and returns only when you have at least C<$time> seconds |
331 | of cpu time till the next tick. The slot is only valid till the next cede. |
331 | of cpu time till the next tick. The slot is only valid till the next cede. |
|
|
332 | |
|
|
333 | The optional C<$name> can be used to identify the job to run. It might be |
|
|
334 | used for statistical purposes and should identify the same time-class. |
332 | |
335 | |
333 | Useful for short background jobs. |
336 | Useful for short background jobs. |
334 | |
337 | |
335 | =cut |
338 | =cut |
336 | |
339 | |
… | |
… | |
363 | Coro::schedule; |
366 | Coro::schedule; |
364 | } |
367 | } |
365 | } |
368 | } |
366 | }; |
369 | }; |
367 | |
370 | |
368 | sub get_slot($;$) { |
371 | sub get_slot($;$$) { |
369 | my ($time, $pri) = @_; |
372 | my ($time, $pri, $name) = @_; |
370 | |
373 | |
|
|
374 | $time = $TICK * .6 if $time > $TICK * .6; |
|
|
375 | my $sig = new Coro::Signal; |
|
|
376 | |
371 | push @SLOT_QUEUE, [$time, $pri, my $sig = new Coro::Signal]; |
377 | push @SLOT_QUEUE, [$time, $pri, $sig, $name]; |
372 | @SLOT_QUEUE = sort { $b->[1] <=> $a->[1] } @SLOT_QUEUE; |
378 | @SLOT_QUEUE = sort { $b->[1] <=> $a->[1] } @SLOT_QUEUE; |
373 | $SLOT_QUEUE->ready; |
379 | $SLOT_QUEUE->ready; |
374 | $sig->wait; |
380 | $sig->wait; |
375 | } |
381 | } |
376 | |
382 | |