Applications may use EventFD
instead of a pipe in cases where a pipe is only used to signal events. The kernel overhead for an EventFD
descriptor is much lower than that of a pipe.
As of Linux 2.6.30, an EventFD
may also be used as a semaphore.
the maximum value that may be stored in an EventFD
, currently 0xfffffffffffffffe
EventFD.new(initial_value [, flags]) -> EventFD IO object source
Creates an EventFD
object. initial_value
is a non-negative Integer to start the internal counter at.
Starting with Linux 2.6.27, flags
may be a mask that consists of any of the following:
:CLOEXEC - set the close-on-exec flag on the new object
:NONBLOCK - set the non-blocking I/O flag on the new object
Since Linux 2.6.30, flags
may also include:
:SEMAPHORE - provides semaphore-like semantics (see EventFD#value
)
efd.incr(integer_value[, nonblock ]) -> true or nil source
Increments the internal counter by integer_value
which is an unsigned Integer value.
If nonblock
is specified and true, this will return nil
if the internal counter will overflow the value of EventFD::MAX. Otherwise it will block until the counter may be incremented without overflowing.
efd.value([nonblock]) -> Integer or nil source
If not created as a semaphore, returns the current value and resets the counter to zero.
If created as a semaphore, this decrements the counter value by one and returns 1
.
If the counter is zero at the time of the call, this will block until the counter becomes non-zero unless nonblock
is true
, in which case it returns nil
.
Parent: IO
Pages
Classes
Methods
mail archives: https://yhbt.net/sleepy-penguin/ public: sleepy-penguin@yhbt.net source code: git clone https://yhbt.net/sleepy_penguin.git