Data-Sync-Shared
view release on metacpan or search on metacpan
Operations
$cv->lock; # acquire built-in mutex
$cv->unlock; # release built-in mutex
my $ok = $cv->try_lock; # non-blocking
my $ok = $cv->wait; # unlock, wait for signal, re-lock
my $ok = $cv->wait($timeout); # with timeout
$cv->signal; # wake one waiter
$cv->broadcast; # wake all waiters
my $ok = $cv->wait_while(\&pred); # loop until pred returns false
my $ok = $cv->wait_while(\&pred, $timeout); # with timeout
"wait" must be called while holding the mutex. Returns 1 on
signal/broadcast, 0 on timeout. The mutex is always re-acquired before
"wait" returns.
"wait_while" calls "wait" in a loop until the predicate coderef returns
false. Returns 1 if predicate became false, 0 on timeout.
Guard
my $g = $cv->lock_guard; # unlock on scope exit
Data::Sync::Shared::Once
Constructors
my $once = Data::Sync::Shared::Once->new($path);
my $once = Data::Sync::Shared::Once->new(undef);
my $once = Data::Sync::Shared::Once->new_memfd($name);
my $once = Data::Sync::Shared::Once->new_from_fd($fd);
Operations
my $init = $once->enter; # try + wait, infinite
my $init = $once->enter($timeout); # with timeout
$once->done; # mark initialization complete
my $ok = $once->is_done; # check without blocking
$once->reset; # reset to uninitialized state
"enter" returns true for exactly one process (the initializer). All
others block until "done" is called, then return false. If the
initializer dies, stale PID detection elects a new one.
Common Methods
All primitives support:
my $p = $obj->path; # backing file path (undef if anon)
my $fd = $obj->memfd; # memfd fd (-1 if file-backed/anon)
$obj->sync; # msync â flush to disk
$obj->unlink; # remove backing file
Class->unlink($path); # class method form
my $s = $obj->stats; # diagnostic hashref
Stats keys vary by type. All counters are approximate under concurrency.
Semaphore: "value", "max", "waiters", "mmap_size", "acquires",
"releases", "waits", "timeouts", "recoveries".
Barrier: "parties", "arrived", "generation", "waiters", "mmap_size",
"waits", "releases", "timeouts".
RWLock: "state" ("unlocked", "read_locked", "write_locked"), "readers",
"waiters", "mmap_size", "acquires", "releases", "recoveries".
Condvar: "waiters", "signals", "mmap_size", "acquires", "releases",
"waits", "timeouts", "recoveries".
Once: "state" ("init", "running", "done"), "is_done", "waiters",
"mmap_size", "acquires", "releases", "waits", "timeouts", "recoveries".
eventfd Integration
my $fd = $obj->eventfd; # create eventfd, returns fd
$obj->eventfd_set($fd); # use existing fd (e.g. from fork)
my $fd = $obj->fileno; # current eventfd (-1 if none)
$obj->notify; # signal eventfd
my $n = $obj->eventfd_consume; # drain notification counter
Notification is opt-in. Use with EV or other event loops.
SEE ALSO
Data::Buffer::Shared - typed shared array
Data::HashMap::Shared - concurrent hash table
Data::Queue::Shared - FIFO queue
Data::PubSub::Shared - publish-subscribe ring
Data::ReqRep::Shared - request-reply
Data::Pool::Shared - fixed-size object pool
Data::Stack::Shared - LIFO stack
Data::Deque::Shared - double-ended queue
Data::Log::Shared - append-only log (WAL)
Data::Heap::Shared - priority queue
Data::Graph::Shared - directed weighted graph
Data::BitSet::Shared - shared bitset (lock-free per-bit ops)
Data::RingBuffer::Shared - fixed-size overwriting ring buffer
AUTHOR
vividsnow
LICENSE
This is free software; you can redistribute it and/or modify it under
the same terms as Perl itself.
( run in 1.286 second using v1.01-cache-2.11-cpan-39bf76dae61 )