mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2026-03-21 17:49:58 -05:00
ControllerInterface/evdev: Replace a select() call with poll().
select() should not be used on Linux. "select() can monitor only file descriptors numbers that are less than FD_SETSIZE".
This commit is contained in:
parent
d58e7ca932
commit
ae17a06cf8
|
|
@ -12,6 +12,7 @@
|
|||
#include <fcntl.h>
|
||||
#include <libudev.h>
|
||||
#include <sys/eventfd.h>
|
||||
#include <sys/poll.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "Common/Assert.h"
|
||||
|
|
@ -21,6 +22,7 @@
|
|||
#include "Common/ScopeGuard.h"
|
||||
#include "Common/StringUtil.h"
|
||||
#include "Common/Thread.h"
|
||||
#include "Common/UnixUtil.h"
|
||||
#include "Common/WorkQueueThread.h"
|
||||
#include "InputCommon/ControllerInterface/ControllerInterface.h"
|
||||
|
||||
|
|
@ -343,15 +345,19 @@ void InputBackend::HotplugThreadFunc()
|
|||
|
||||
while (m_hotplug_thread_running.IsSet())
|
||||
{
|
||||
fd_set fds;
|
||||
std::array<pollfd, 2> pollfds{
|
||||
pollfd{.fd = monitor_fd, .events = POLLIN},
|
||||
pollfd{.fd = m_wakeup_eventfd, .events = POLLIN},
|
||||
};
|
||||
|
||||
FD_ZERO(&fds);
|
||||
FD_SET(monitor_fd, &fds);
|
||||
FD_SET(m_wakeup_eventfd, &fds);
|
||||
const int poll_result = UnixUtil::RetryOnEINTR(poll, pollfds.data(), pollfds.size(), -1);
|
||||
if (poll_result < 0)
|
||||
{
|
||||
ERROR_LOG_FMT(CONTROLLERINTERFACE, "evdev: poll: {}", Common::LastStrerrorString());
|
||||
break;
|
||||
}
|
||||
|
||||
const int ret =
|
||||
select(std::max(monitor_fd, m_wakeup_eventfd) + 1, &fds, nullptr, nullptr, nullptr);
|
||||
if (ret < 1 || !FD_ISSET(monitor_fd, &fds))
|
||||
if (pollfds[0].revents == 0)
|
||||
continue;
|
||||
|
||||
udev_device* const dev = udev_monitor_receive_device(monitor);
|
||||
|
|
@ -401,8 +407,7 @@ void InputBackend::StartHotplugThread()
|
|||
return;
|
||||
}
|
||||
|
||||
m_wakeup_eventfd = eventfd(0, 0);
|
||||
ASSERT_MSG(CONTROLLERINTERFACE, m_wakeup_eventfd != -1, "Couldn't create eventfd.");
|
||||
m_wakeup_eventfd = UnixUtil::CreateEventFD(0, 0);
|
||||
m_hotplug_thread = std::thread(&InputBackend::HotplugThreadFunc, this);
|
||||
}
|
||||
|
||||
|
|
@ -415,7 +420,7 @@ void InputBackend::StopHotplugThread()
|
|||
return;
|
||||
}
|
||||
|
||||
// Write something to efd so that select() stops blocking.
|
||||
// Write something to efd so that poll() stops blocking.
|
||||
const uint64_t value = 1;
|
||||
static_cast<void>(!write(m_wakeup_eventfd, &value, sizeof(uint64_t)));
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user