diff options
author | Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> | 2022-08-19 14:16:15 +0300 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2022-08-19 15:44:28 +0300 |
commit | bf3dbaece91e7f9be00923a225a62a918bf71f5b (patch) | |
tree | e22642e0d928e5827a781cea7d23743657b686b1 /src/py/libcamera/py_camera_manager.cpp | |
parent | de7f1aa591881e112b67ec4f6507a6079b226089 (diff) |
py: Switch to non-blocking eventfd
Blocking wait can be easily implemented on top in Python, so rather than
supporting only blocking reads, or supporting both non-blocking and
blocking reads, let's support only non-blocking reads.
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'src/py/libcamera/py_camera_manager.cpp')
-rw-r--r-- | src/py/libcamera/py_camera_manager.cpp | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/src/py/libcamera/py_camera_manager.cpp b/src/py/libcamera/py_camera_manager.cpp index ea4ae825..9ccb7aad 100644 --- a/src/py/libcamera/py_camera_manager.cpp +++ b/src/py/libcamera/py_camera_manager.cpp @@ -24,7 +24,7 @@ PyCameraManager::PyCameraManager() cameraManager_ = std::make_unique<CameraManager>(); - int fd = eventfd(0, EFD_CLOEXEC); + int fd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK); if (fd == -1) throw std::system_error(errno, std::generic_category(), "Failed to create eventfd"); @@ -62,7 +62,13 @@ py::list PyCameraManager::cameras() std::vector<py::object> PyCameraManager::getReadyRequests() { - readFd(); + int ret = readFd(); + + if (ret == -EAGAIN) + return std::vector<py::object>(); + + if (ret != 0) + throw std::system_error(-ret, std::generic_category()); std::vector<py::object> py_reqs; @@ -96,12 +102,18 @@ void PyCameraManager::writeFd() LOG(Python, Fatal) << "Unable to write to eventfd"; } -void PyCameraManager::readFd() +int PyCameraManager::readFd() { uint8_t buf[8]; - if (read(eventFd_.get(), buf, 8) != 8) - throw std::system_error(errno, std::generic_category()); + ssize_t ret = read(eventFd_.get(), buf, 8); + + if (ret == 8) + return 0; + else if (ret < 0) + return -errno; + else + return -EIO; } void PyCameraManager::pushRequest(Request *req) |