Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Adress more code reviews
- initval is a uint32_t
- improve documentation
- add whatsnew

Signed-off-by: Christian Heimes <[email protected]>
  • Loading branch information
tiran committed Nov 13, 2020
commit 9c0dff53033bc65d1277e67d3fdecc07da75a8cf
38 changes: 24 additions & 14 deletions Doc/library/os.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3283,6 +3283,14 @@ features:
:func:`~select.select`, :func:`~select.poll` and similar. By default, the
new file descriptor is :ref:`non-inheritable <fd_inheritance>`.

*initval* is the initial value of the event counter. The initial value
must be an 32 bit unsigned integer. Please note that the initial value is
limited to a 32 bit unsigned int although the event counter is an unsigned
64 bit integer with a maximum value of 2\ :sup:`64`\ -\ 2.

*flags* can be constructed from :const:`EFD_CLOEXEC`,
:const:`EFD_NONBLOCK`, and :const:`EFD_SEMAPHORE`.

If :const:`EFD_SEMAPHORE` is specified and the event counter is non-zero,
:func:`eventfd_read` returns 1 and decrements the counter by one.

Expand All @@ -3292,53 +3300,55 @@ features:

If the event counter is zero, :func:`eventfd_read` blocks.

:func:`eventfd_write` increments the event counter.

*initval* is the initial value of the event counter. It must be an
unsigned integer between 0 and 2\ :sup:`64`\ -\ 2.

*flags* can be constructed from :const:`EFD_CLOEXEC`,
:const:`EFD_NONBLOCK`, and :const:`EFD_SEMAPHORE`.
:func:`eventfd_write` increments the event counter. Write blocks if the
write operation would increment the counter to a value larger than
2\ :sup:`64`\ -\ 2.

.. availability:: Linux 2.6.27 or newer with glibc 2.8 or newer.

.. versionadded:: 3.10

.. function:: eventfd_read(fd)

Read value from an :func:`eventfd` file descriptor and return
an unsigned integer between 0 and 2\ :sup:`64`\ -\ 2. The function does
not verify that *fd* is an :func:`eventfd`.
Read value from an :func:`eventfd` file descriptor and return a 64 bit
unsigned int. The function does not verify that *fd* is an :func:`eventfd`.

.. availability:: See :func:`eventfd`

.. versionadded:: 3.10

.. function:: eventfd_write(fd, value)

Add value to an :func:`eventfd` file descriptor. *value* must be
an unsigned integer between 0 and 2\ :sup:`64`\ -\ 2. The function does
not verify that *fd* is an :func:`eventfd`.
Add value to an :func:`eventfd` file descriptor. *value* must be a 64 bit
unsigned int. The function does not verify that *fd* is an :func:`eventfd`.

.. availability:: See :func:`eventfd`

.. versionadded:: 3.10

.. data:: EFD_CLOEXEC

Set close-on-exec flag for new :func:`eventfd` file descriptor.

.. availability:: See :func:`eventfd`

.. versionadded:: 3.10

.. data:: EFD_NONBLOCK

Set :const:`O_NONBLOCK` status flag for new :func:`eventfd` file
descriptor.

.. availability:: See :func:`eventfd`

.. versionadded:: 3.10

.. data:: EFD_SEMAPHORE

Provide semaphore-like semantics for reads from a :func:`eventfd` file
descriptor. On read the internal counter is decremented by one.

.. availability:: Linux 2.6.30 or newer
.. availability:: Linux 2.6.30 or newer with glibc 2.8 or newer.

.. versionadded:: 3.10

Expand Down
4 changes: 4 additions & 0 deletions Doc/whatsnew/3.10.rst
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ os
Added :func:`os.cpu_count()` support for VxWorks RTOS.
(Contributed by Peixing Xin in :issue:`41440`.)

A new :func:`os.eventfd` function and related helpers were added to wrap the
``eventfd2`` syscall on Linux
(Contributed by Christian Heimes in :issue:`41001`.)

py_compile
----------

Expand Down
4 changes: 2 additions & 2 deletions Modules/clinic/posixmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 4 additions & 10 deletions Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -12877,12 +12877,10 @@ Creates and returns an event notification file descriptor.
static PyObject *
os_eventfd_impl(PyObject *module, unsigned int initval, int flags)
/*[clinic end generated code: output=ce9c9bbd1446f2de input=66203e3c50c4028b]*/

{
/* initval is limited to uint32_t, internal counter is uint64_t */
int fd;
if (initval > (PY_ULLONG_MAX - 1)) {
PyErr_SetString(PyExc_OverflowError, "initval too large");
return NULL;
}
Py_BEGIN_ALLOW_THREADS
fd = eventfd(initval, flags);
Py_END_ALLOW_THREADS
Expand Down Expand Up @@ -12921,18 +12919,14 @@ os.eventfd_write
fd: fildes
value: unsigned_long_long

Write eventfd value
Write eventfd value.
[clinic start generated code]*/

static PyObject *
os_eventfd_write_impl(PyObject *module, int fd, unsigned long long value)
/*[clinic end generated code: output=bebd9040bbf987f5 input=82da3dd0d6e62f28]*/
/*[clinic end generated code: output=bebd9040bbf987f5 input=156de8555be5a949]*/
{
int result;
if (value > (PY_ULLONG_MAX - 1)) {
PyErr_SetString(PyExc_OverflowError, "value too large");
return NULL;
}
Py_BEGIN_ALLOW_THREADS
result = eventfd_write(fd, value);
Py_END_ALLOW_THREADS
Expand Down