@@ -3276,6 +3276,102 @@ features:
32763276 .. versionadded :: 3.8
32773277
32783278
3279+ .. function :: eventfd(initval[, flags=os.EFD_CLOEXEC])
3280+
3281+ Create and return an event file descriptor. The file descriptors supports
3282+ raw :func: `read ` and :func: `write ` with a buffer size of 8,
3283+ :func: `~select.select `, :func: `~select.poll ` and similar. See man page
3284+ :manpage: `eventfd(2)` for more information. By default, the
3285+ new file descriptor is :ref: `non-inheritable <fd_inheritance >`.
3286+
3287+ *initval * is the initial value of the event counter. The initial value
3288+ must be an 32 bit unsigned integer. Please note that the initial value is
3289+ limited to a 32 bit unsigned int although the event counter is an unsigned
3290+ 64 bit integer with a maximum value of 2\ :sup: `64`\ -\ 2.
3291+
3292+ *flags * can be constructed from :const: `EFD_CLOEXEC `,
3293+ :const: `EFD_NONBLOCK `, and :const: `EFD_SEMAPHORE `.
3294+
3295+ If :const: `EFD_SEMAPHORE ` is specified and the event counter is non-zero,
3296+ :func: `eventfd_read ` returns 1 and decrements the counter by one.
3297+
3298+ If :const: `EFD_SEMAPHORE ` is not specified and the event counter is
3299+ non-zero, :func: `eventfd_read ` returns the current event counter value and
3300+ resets the counter to zero.
3301+
3302+ If the event counter is zero and :const: `EFD_NONBLOCK ` is not
3303+ specified, :func: `eventfd_read ` blocks.
3304+
3305+ :func: `eventfd_write ` increments the event counter. Write blocks if the
3306+ write operation would increment the counter to a value larger than
3307+ 2\ :sup: `64`\ -\ 2.
3308+
3309+ Example::
3310+
3311+ import os
3312+
3313+ # semaphore with start value '1'
3314+ fd = os.eventfd(1, os.EFD_SEMAPHORE | os.EFC_CLOEXEC)
3315+ try:
3316+ # acquire semaphore
3317+ v = os.eventfd_read(fd)
3318+ try:
3319+ do_work()
3320+ finally:
3321+ # release semaphore
3322+ os.eventfd_write(fd, v)
3323+ finally:
3324+ os.close(fd)
3325+
3326+ .. availability :: Linux 2.6.27 or newer with glibc 2.8 or newer.
3327+
3328+ .. versionadded :: 3.10
3329+
3330+ .. function :: eventfd_read(fd)
3331+
3332+ Read value from an :func: `eventfd ` file descriptor and return a 64 bit
3333+ unsigned int. The function does not verify that *fd * is an :func: `eventfd `.
3334+
3335+ .. availability :: See :func:`eventfd`
3336+
3337+ .. versionadded :: 3.10
3338+
3339+ .. function :: eventfd_write(fd, value)
3340+
3341+ Add value to an :func: `eventfd ` file descriptor. *value * must be a 64 bit
3342+ unsigned int. The function does not verify that *fd * is an :func: `eventfd `.
3343+
3344+ .. availability :: See :func:`eventfd`
3345+
3346+ .. versionadded :: 3.10
3347+
3348+ .. data :: EFD_CLOEXEC
3349+
3350+ Set close-on-exec flag for new :func: `eventfd ` file descriptor.
3351+
3352+ .. availability :: See :func:`eventfd`
3353+
3354+ .. versionadded :: 3.10
3355+
3356+ .. data :: EFD_NONBLOCK
3357+
3358+ Set :const: `O_NONBLOCK ` status flag for new :func: `eventfd ` file
3359+ descriptor.
3360+
3361+ .. availability :: See :func:`eventfd`
3362+
3363+ .. versionadded :: 3.10
3364+
3365+ .. data :: EFD_SEMAPHORE
3366+
3367+ Provide semaphore-like semantics for reads from a :func: `eventfd ` file
3368+ descriptor. On read the internal counter is decremented by one.
3369+
3370+ .. availability :: Linux 2.6.30 or newer with glibc 2.8 or newer.
3371+
3372+ .. versionadded :: 3.10
3373+
3374+
32793375Linux extended attributes
32803376~~~~~~~~~~~~~~~~~~~~~~~~~
32813377
0 commit comments