diff options
| author | Damien George <damien@micropython.org> | 2023-08-01 12:39:39 +1000 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2023-08-07 12:11:40 +1000 |
| commit | ef71028f77e4a6fc449c64906ebad0a160f35240 (patch) | |
| tree | 5d57456261db48eecc98d0cccb5428eb46e71cfa /extmod/vfs_posix_file.c | |
| parent | ebc655634650274727c71881e0d36ff738793928 (diff) | |
extmod/modselect: Add optimisation to use system poll when possible.
A previous commit removed the unix-specific select module implementation
and made unix use the common one.
This commit adds an optimisation so that the system poll function is used
when polling objects that have a file descriptor. With this optimisation
enabled, if code registers both file-descriptor-based objects, and non-
file-descriptor-based objects with select.poll() then the following occurs:
- the system poll is called for all file-descriptor-based objects with a
timeout of 1ms
- then the bare-metal polling implementation is used for remaining objects,
which calls into their ioctl method (which can be in C or Python)
In the case where all objects have file descriptors, the system poll is
called with the full timeout requested by the caller. That makes it as
efficient as possible in the case everything has a file descriptor.
Benefits of this approach:
- all ports use the same select module implementation
- the unix port now supports polling of all objects and matches bare metal
implementations
- it's still efficient for existing cases where only files and sockets are
polled (on unix)
- the bare metal implementation does not change
- polling of SSL objects will now work on unix by calling in to the ioctl
method on SSL objects (this is required for asyncio ssl support)
Note that extmod/vfs_posix_file.c has poll disable when the optimisation is
enabled, because the code is not reachable when the optimisation is used.
Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'extmod/vfs_posix_file.c')
| -rw-r--r-- | extmod/vfs_posix_file.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/extmod/vfs_posix_file.c b/extmod/vfs_posix_file.c index 41d7622b3..d70bc4738 100644 --- a/extmod/vfs_posix_file.c +++ b/extmod/vfs_posix_file.c @@ -188,7 +188,7 @@ STATIC mp_uint_t vfs_posix_file_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_ return 0; case MP_STREAM_GET_FILENO: return o->fd; - #if MICROPY_PY_SELECT + #if MICROPY_PY_SELECT && !MICROPY_PY_SELECT_POSIX_OPTIMISATIONS case MP_STREAM_POLL: { #ifdef _WIN32 mp_raise_NotImplementedError(MP_ERROR_TEXT("poll on file not available on win32")); |
