Use safe thread class instead of std::thread

This commit is contained in:
pixl
2020-06-24 17:31:16 -04:00
parent d84363019b
commit 4ba9248038
7 changed files with 74 additions and 23 deletions

View File

@@ -17,6 +17,8 @@
*/
#include "DeviceMonitor.h"
#include "../../util/thread.h"
#include "../../util.h"
#include <thread>
#include <system_error>
@@ -96,13 +98,19 @@ void DeviceMonitor::run()
std::string devnode = udev_device_get_devnode(device);
if (action == "add")
std::thread([this](const std::string name) {
thread::spawn([this, name=devnode]() {
this->addDevice(name);
}, devnode).detach();
}, [name=devnode](std::exception& e){
log_printf(WARN, "Error adding device %s: %s",
name.c_str(), e.what());
});
else if (action == "remove")
std::thread([this](const std::string name) {
thread::spawn([this, name=devnode]() {
this->removeDevice(name);
}, devnode).detach();
}, [name=devnode](std::exception& e){
log_printf(WARN, "Error removing device %s: %s",
name.c_str(), e.what());
});
udev_device_unref (device);
}
@@ -149,9 +157,12 @@ void DeviceMonitor::enumerate()
std::string devnode = udev_device_get_devnode(device);
udev_device_unref(device);
std::thread([this](const std::string& name) {
thread::spawn([this, name=devnode]() {
this->addDevice(name);
}, devnode).detach();
}, [name=devnode](std::exception& e){
log_printf(ERROR, "Error adding device %s: %s",
name.c_str(), e.what());
});
}
udev_enumerate_unref(udev_enum);