NAME

Linux::Event::Wakeup - eventfd-backed wakeups for Linux::Event

SYNOPSIS

use v5.36;
use Linux::Event;

my $loop  = Linux::Event->new;
my $waker = $loop->waker;

# Watch it like any other readable fd:
$loop->watch($waker->fh,
  read => sub ($loop, $fh, $watcher) {
    my $count = $waker->drain;
    ... drain your own queue ...
  },
);

# From another thread (or a forked child), poke the loop:
$waker->signal;

DESCRIPTION

This module provides a minimal, Linux-native wakeup primitive for Linux::Event based on eventfd(2). It is intended to be used as a building block for thread and process integration without adding policy to the core loop.

The wakeup is expressed as a normal readable filehandle so it can be used with $loop->watch(...) like any other fd.

SEMANTICS

The semantics contract for the single-waker model is:

  • Exactly one waker per loop (cached by $loop->waker).

  • Created lazily on first use; never destroyed during loop lifetime.

  • No implicit watcher is installed.

  • signal() is safe from any thread.

  • drain() is non-blocking and returns the coalesced count.

METHODS

fh

my $fh = $waker->fh;

Returns the readable filehandle for this eventfd.

signal

$waker->signal;      # increment by 1
$waker->signal($n);  # increment by $n

Increments the eventfd counter. Multiple signals coalesce in the kernel.

drain

my $count = $waker->drain;

Drains the eventfd counter (non-blocking) and returns the total number of signals coalesced since the last drain.

DEPENDENCIES

Wakeup support requires Linux::FD::Event (part of the Linux::FD distribution). The dependency is loaded lazily so you can still use the core loop features (timers and I/O watchers) without it.

AUTHOR

Joshua S. Day

LICENSE

Same terms as Perl itself.

VERSION

This document describes Linux::Event::Wakeup version 0.006.