… | |
… | |
32 | use Opcode; |
32 | use Opcode; |
33 | use Safe; |
33 | use Safe; |
34 | use Safe::Hole; |
34 | use Safe::Hole; |
35 | use Storable (); |
35 | use Storable (); |
36 | |
36 | |
|
|
37 | use Guard (); |
37 | use Coro (); |
38 | use Coro (); |
38 | use Coro::State; |
39 | use Coro::State; |
39 | use Coro::Handle; |
40 | use Coro::Handle; |
40 | use Coro::EV; |
41 | use Coro::EV; |
41 | use Coro::AnyEvent; |
42 | use Coro::AnyEvent; |
… | |
… | |
330 | Wait until the given lock is available. See cf::lock_acquire. |
331 | Wait until the given lock is available. See cf::lock_acquire. |
331 | |
332 | |
332 | =item my $lock = cf::lock_acquire $string |
333 | =item my $lock = cf::lock_acquire $string |
333 | |
334 | |
334 | Wait until the given lock is available and then acquires it and returns |
335 | Wait until the given lock is available and then acquires it and returns |
335 | a Coro::guard object. If the guard object gets destroyed (goes out of scope, |
336 | a L<Guard> object. If the guard object gets destroyed (goes out of scope, |
336 | for example when the coroutine gets canceled), the lock is automatically |
337 | for example when the coroutine gets canceled), the lock is automatically |
337 | returned. |
338 | returned. |
338 | |
339 | |
339 | Locks are *not* recursive, locking from the same coro twice results in a |
340 | Locks are *not* recursive, locking from the same coro twice results in a |
340 | deadlocked coro. |
341 | deadlocked coro. |
… | |
… | |
374 | lock_wait $key; |
375 | lock_wait $key; |
375 | |
376 | |
376 | $LOCK{$key} = []; |
377 | $LOCK{$key} = []; |
377 | $LOCKER{$key} = $Coro::current;#d# |
378 | $LOCKER{$key} = $Coro::current;#d# |
378 | |
379 | |
379 | Coro::guard { |
380 | Guard::guard { |
380 | delete $LOCKER{$key};#d# |
381 | delete $LOCKER{$key};#d# |
381 | # wake up all waiters, to be on the safe side |
382 | # wake up all waiters, to be on the safe side |
382 | $_->ready for @{ delete $LOCK{$key} }; |
383 | $_->ready for @{ delete $LOCK{$key} }; |
383 | } |
384 | } |
384 | } |
385 | } |
… | |
… | |
390 | } |
391 | } |
391 | |
392 | |
392 | sub freeze_mainloop { |
393 | sub freeze_mainloop { |
393 | tick_inhibit_inc; |
394 | tick_inhibit_inc; |
394 | |
395 | |
395 | Coro::guard \&tick_inhibit_dec; |
396 | &Guard::guard (\&tick_inhibit_dec); |
396 | } |
397 | } |
397 | |
398 | |
398 | =item cf::periodic $interval, $cb |
399 | =item cf::periodic $interval, $cb |
399 | |
400 | |
400 | Like EV::periodic, but randomly selects a starting point so that the actions |
401 | Like EV::periodic, but randomly selects a starting point so that the actions |