mirror of
https://github.com/commaai/msgq.git
synced 2026-06-11 07:24:45 +08:00
retry ioctls while errno == EINTR (#191)
This commit is contained in:
@@ -15,6 +15,16 @@
|
||||
|
||||
#include "visionbuf.h"
|
||||
|
||||
// keep trying if x gets interrupted by a signal
|
||||
#define HANDLE_EINTR(x) \
|
||||
({ \
|
||||
decltype(x) ret; \
|
||||
int try_cnt = 0; \
|
||||
do { \
|
||||
ret = (x); \
|
||||
} while (ret == -1 && errno == EINTR && try_cnt++ < 100); \
|
||||
ret; \
|
||||
})
|
||||
|
||||
// just hard-code these for convenience
|
||||
// size_t device_page_size = 0;
|
||||
@@ -47,12 +57,12 @@ void VisionBuf::allocate(size_t len) {
|
||||
ion_alloc.heap_id_mask = 1 << ION_IOMMU_HEAP_ID;
|
||||
ion_alloc.flags = ION_FLAG_CACHED;
|
||||
|
||||
err = ioctl(ion_fd, ION_IOC_ALLOC, &ion_alloc);
|
||||
err = HANDLE_EINTR(ioctl(ion_fd, ION_IOC_ALLOC, &ion_alloc));
|
||||
assert(err == 0);
|
||||
|
||||
struct ion_fd_data ion_fd_data = {0};
|
||||
ion_fd_data.handle = ion_alloc.handle;
|
||||
err = ioctl(ion_fd, ION_IOC_SHARE, &ion_fd_data);
|
||||
err = HANDLE_EINTR(ioctl(ion_fd, ION_IOC_SHARE, &ion_fd_data));
|
||||
assert(err == 0);
|
||||
|
||||
void *addr = mmap(NULL, ion_alloc.len,
|
||||
@@ -78,7 +88,7 @@ void VisionBuf::import(){
|
||||
// Get handle
|
||||
struct ion_fd_data fd_data = {0};
|
||||
fd_data.fd = this->fd;
|
||||
err = ioctl(ion_fd, ION_IOC_IMPORT, &fd_data);
|
||||
err = HANDLE_EINTR(ioctl(ion_fd, ION_IOC_IMPORT, &fd_data));
|
||||
assert(err == 0);
|
||||
|
||||
this->handle = fd_data.handle;
|
||||
@@ -122,7 +132,7 @@ int VisionBuf::sync(int dir) {
|
||||
ION_IOC_INV_CACHES : ION_IOC_CLEAN_CACHES;
|
||||
|
||||
custom_data.arg = (unsigned long)&flush_data;
|
||||
return ioctl(ion_fd, ION_IOC_CUSTOM, &custom_data);
|
||||
return HANDLE_EINTR(ioctl(ion_fd, ION_IOC_CUSTOM, &custom_data));
|
||||
}
|
||||
|
||||
int VisionBuf::free() {
|
||||
@@ -140,5 +150,5 @@ int VisionBuf::free() {
|
||||
if (err != 0) return err;
|
||||
|
||||
struct ion_handle_data handle_data = {.handle = this->handle};
|
||||
return ioctl(ion_fd, ION_IOC_FREE, &handle_data);
|
||||
return HANDLE_EINTR(ioctl(ion_fd, ION_IOC_FREE, &handle_data));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user