-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support input device hot-plugging and removal via udev #68
base: main
Are you sure you want to change the base?
Conversation
backend/linux_input.c
Outdated
@@ -170,6 +260,12 @@ void *twin_linux_input_create(twin_screen_t *screen) | |||
twin_set_file(dummy, tm->fd, TWIN_READ, tm); | |||
#endif | |||
|
|||
/* Start event handling thread */ | |||
if (pthread_create(&tm->udev_thread, NULL, twin_linux_udev_thread, tm)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you create yet another thread for event handling? Can you deal with udev in the existing thread?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We indeed require only one thread, the udev
and evdev
are now handled by one pollfd
array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent. You have discovered how effective I/O multiplexing can be for optimizing the code.
udev (userspace /dev) is a device manager for the Linux kernel. By monitoring "add" and "remove" events from udev, we can dynamically update the event device file descriptors table to enable device hot-plugging and removal. Close sysprog21#61
3661174
to
e9166a0
Compare
@@ -106,6 +106,7 @@ endif | |||
|
|||
ifeq ($(CONFIG_BACKEND_FBDEV), y) | |||
BACKEND = fbdev | |||
TARGET_LIBS += -ludev |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mention libudev-dev
dependency in top-level document.
/* Open Linux udev (user space device manager) */ | ||
int udev_fd = twin_linux_udev_init(&udev, &mon); | ||
if (udev_fd < 0) { | ||
exit(2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The exit
call here seems too harsh. Even if the input event thread fails, other parts of Mado should continue running - this would allow programmers to see the error messages and diagnose what went wrong. Consider handling the failure more gracefully rather than terminating the entire program.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rebase the latest main
branch and mention the dependent package libuuid
in the top-level documentation.
Overview
udev
(userspace /dev
) is a device manager for the Linux kernel. By monitoringadd
andremove
events fromudev
, we can dynamically update the event device file descriptors table to enable device hot-plugging and removal.Prerequisites
To test the modified code, compile
mado
with theLinux framebuffer
backend.Test procedure
Ctrl+Alt+Fn
(e.g.,Ctrl+Alt+F3
) and then execute:Ctrl+Alt+F1
.