From e88c7b29ea9ec9fcd6ac6b15c965085152100d2e Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 18 Jun 2017 18:19:17 +0200 Subject: get rid of "volatile" abuse We heavily used "volatile bool" to check if the thread loop should stop. But this functionality is already provided by Qt5's QThread::requestInterruption. In other cases, "volatile" is wonderfully underspecified so it's better to ditch its usage in favor of std::atomic. At the time we don't appear to be using the "volatile" keyword except when calling win32's Interlocked*() family of functions as necessary. In freetrackclient's header the "volatile" qualifier was used as part of a typedef. This doesn't work. Use it as part of data declaration. --- tracker-udp/ftnoir_tracker_udp.cpp | 10 +++++----- tracker-udp/ftnoir_tracker_udp.h | 1 - 2 files changed, 5 insertions(+), 6 deletions(-) (limited to 'tracker-udp') diff --git a/tracker-udp/ftnoir_tracker_udp.cpp b/tracker-udp/ftnoir_tracker_udp.cpp index 5f95ab5a..e2d6fc93 100644 --- a/tracker-udp/ftnoir_tracker_udp.cpp +++ b/tracker-udp/ftnoir_tracker_udp.cpp @@ -13,13 +13,12 @@ udp::udp() : last_recv_pose { 0,0,0, 0,0,0 }, - last_recv_pose2 { 0,0,0, 0,0,0 }, - should_quit(false) + last_recv_pose2 { 0,0,0, 0,0,0 } {} udp::~udp() { - should_quit = true; + requestInterruption(); wait(); } @@ -28,9 +27,10 @@ void udp::run() QByteArray datagram; datagram.resize(sizeof(last_recv_pose)); - should_quit = !sock.bind(QHostAddress::Any, quint16(s.port), QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint); + if (!sock.bind(QHostAddress::Any, quint16(s.port), QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint)) + return; - while (!should_quit) + while (!isInterruptionRequested()) { if (sock.hasPendingDatagrams()) { diff --git a/tracker-udp/ftnoir_tracker_udp.h b/tracker-udp/ftnoir_tracker_udp.h index b6e0aefd..0167a005 100644 --- a/tracker-udp/ftnoir_tracker_udp.h +++ b/tracker-udp/ftnoir_tracker_udp.h @@ -33,7 +33,6 @@ private: double last_recv_pose[6], last_recv_pose2[6]; QMutex mutex; settings s; - volatile bool should_quit; }; class dialog_udp: public ITrackerDialog -- cgit v1.2.3