From 6f616adf5c158e23755a98d719aaf0aa9bb897c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20H=C3=B6glinger-Stelzer?= Date: Tue, 28 May 2019 21:18:33 +0200 Subject: [PATCH] Fixed x360 notification clean-up --- app/Tester/Tester.cpp | 1 + src/Internal.h | 2 +- src/NotificationRequestPool.cpp | 8 ++++---- src/NotificationRequestPool.h | 3 +-- src/ViGEmClient.cpp | 8 ++++---- src/XusbNotificationRequest.cpp | 2 +- src/XusbNotificationRequest.h | 2 +- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app/Tester/Tester.cpp b/app/Tester/Tester.cpp index 57dc1f0..dc8f4a9 100644 --- a/app/Tester/Tester.cpp +++ b/app/Tester/Tester.cpp @@ -54,6 +54,7 @@ int main() Sleep(10); } + vigem_target_x360_unregister_notification(x360); vigem_target_remove(client, x360); vigem_target_free(x360); vigem_free(client); diff --git a/src/Internal.h b/src/Internal.h index 0520691..a703fec 100644 --- a/src/Internal.h +++ b/src/Internal.h @@ -66,6 +66,6 @@ typedef struct _VIGEM_TARGET_T VIGEM_TARGET_TYPE Type; FARPROC Notification; - std::shared_ptr pool; + std::unique_ptr NotificationPool; } VIGEM_TARGET; diff --git a/src/NotificationRequestPool.cpp b/src/NotificationRequestPool.cpp index b7b2eba..2dd9616 100644 --- a/src/NotificationRequestPool.cpp +++ b/src/NotificationRequestPool.cpp @@ -32,8 +32,7 @@ void NotificationRequestPool::strand_dispatch_worker() const NotificationRequestPool::NotificationRequestPool( PVIGEM_CLIENT client, - PVIGEM_TARGET target, - FARPROC callback + PVIGEM_TARGET target ) : client_(client), target_(target), @@ -73,10 +72,11 @@ NotificationRequestPool::~NotificationRequestPool() noexcept(false) for (auto& wait_handle : wait_handles_) CloseHandle(wait_handle); + for (auto& request : requests_) + request.reset(); + io_svc_->stop(); worker_thread_->join(); - - thread_->join(); } void NotificationRequestPool::operator()() diff --git a/src/NotificationRequestPool.h b/src/NotificationRequestPool.h index d43b216..eaca845 100644 --- a/src/NotificationRequestPool.h +++ b/src/NotificationRequestPool.h @@ -57,8 +57,7 @@ class NotificationRequestPool public: NotificationRequestPool( PVIGEM_CLIENT client, - PVIGEM_TARGET target, - FARPROC callback + PVIGEM_TARGET target ); ~NotificationRequestPool() noexcept(false); diff --git a/src/ViGEmClient.cpp b/src/ViGEmClient.cpp index d42ef63..ebb6192 100644 --- a/src/ViGEmClient.cpp +++ b/src/ViGEmClient.cpp @@ -486,10 +486,9 @@ VIGEM_ERROR vigem_target_x360_register_notification( target->Notification = reinterpret_cast(notification); - target->pool = std::make_shared( + target->NotificationPool = std::make_unique( vigem, - target, - reinterpret_cast(target->Notification) + target ); return VIGEM_ERROR_NONE; @@ -580,7 +579,8 @@ VIGEM_ERROR vigem_target_ds4_register_notification( void vigem_target_x360_unregister_notification(PVIGEM_TARGET target) { - target->Notification = NULL; + target->NotificationPool.reset(); + target->Notification = nullptr; } void vigem_target_ds4_unregister_notification(PVIGEM_TARGET target) diff --git a/src/XusbNotificationRequest.cpp b/src/XusbNotificationRequest.cpp index 1a01cc9..d951b44 100644 --- a/src/XusbNotificationRequest.cpp +++ b/src/XusbNotificationRequest.cpp @@ -64,7 +64,7 @@ bool XusbNotificationRequest::request_async() return (!ret && error == ERROR_IO_PENDING); } -void XusbNotificationRequest::post(boost::asio::io_service::strand strand) const +void XusbNotificationRequest::post(boost::asio::io_service::strand strand) { // prepare queueing library caller notification callback const boost::function