logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

Linux::FD::Event - Event filehandles for Linux

Author

       Leon Timmermans <leont@cpan.org>

Description

       This creates an eventfd object that can be used as an event wait/notify mechanism by userspace
       applications, and by the kernel to notify userspace applications of events. The object contains an
       unsigned 64-bit integer counter that is maintained by the kernel. It has two modes, default and
       semaphore, that differ only in "get" behavior as described below.

Methods

new($initial_value,@flags)
       This creates a new eventfd filehandler. The counter is initialized with the value specified in the
       argument $initial_value. @flags is an optional list of flags, currently limited to 'non-blocking'
       (requires Linux 2.6.27), and 'semaphore' (requires Linux 2.6.30).

   get()
       If the eventfd counter has a non-zero value, and 'semaphore' is not set, then a "get" returns 64 bit
       unsigned integer containing that value, and the counter's value is reset to zero. If 'semaphore' is set,
       it decrements the counter by one and returns one. In either case, if the counter is zero at the time of
       the "get", then the call either blocks until the counter becomes non-zero, or fails with the error EAGAIN
       if the file handle has been made non-blocking.

   add($value)
       A "add" call adds the 64 bit unsigned integer value $value to the counter. The maximum value that may be
       stored in the counter is the largest unsigned 64-bit value minus 1 (i.e., 0xfffffffffffffffe). If the
       addition would cause the counter's value to exceed the maximum, then the "add" either blocks until a
       "get" is performed on the file descriptor, or fails with the error EAGAIN if the file descriptor has been
       made non-blocking. A "add" will fail with the error EINVAL if an attempt is made to write the value
       0xffffffffffffffff.

Name

       Linux::FD::Event - Event filehandles for Linux

Synopsis

        use Linux::FD::Event;

        my $foo = Linux::FD::Event->new(42);
        if (fork) {
            say $foo->get while sleep 1
        }
        else {
            $foo->add($_) while <>;
        }

Version

       version 0.017

See Also