summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2014-09-22 11:50:27 +0200
committerStanislaw Halik <sthalik@misaki.pl>2014-09-22 11:52:55 +0200
commit52d2fd3bf8e3241c9a671a66daaf3150c6d7ed5b (patch)
tree6152cce0c8a40c72eaf8d5f13c1c13930e361f62
parent979372baf8a990e04d2019002b7db6fdb8874dc1 (diff)
udp: cleanup, reduce mtx contention
-rw-r--r--ftnoir_tracker_udp/ftnoir_tracker_udp.cpp26
-rw-r--r--ftnoir_tracker_udp/ftnoir_tracker_udp.h16
2 files changed, 16 insertions, 26 deletions
diff --git a/ftnoir_tracker_udp/ftnoir_tracker_udp.cpp b/ftnoir_tracker_udp/ftnoir_tracker_udp.cpp
index 12699a58..854cedbb 100644
--- a/ftnoir_tracker_udp/ftnoir_tracker_udp.cpp
+++ b/ftnoir_tracker_udp/ftnoir_tracker_udp.cpp
@@ -25,13 +25,7 @@
#include "ftnoir_tracker_udp.h"
#include "facetracknoir/plugin-support.h"
-FTNoIR_Tracker::FTNoIR_Tracker() : should_quit(false)
-{
- should_quit = false;
-
- for (int i = 0; i < 6; i++)
- newHeadPose[i] = 0;
-}
+FTNoIR_Tracker::FTNoIR_Tracker() : last_recv_pose { 0,0,0, 0,0,0 }, should_quit(false) {}
FTNoIR_Tracker::~FTNoIR_Tracker()
{
@@ -40,22 +34,22 @@ FTNoIR_Tracker::~FTNoIR_Tracker()
}
void FTNoIR_Tracker::run() {
- forever {
+ QByteArray datagram;
+ datagram.resize(sizeof(last_recv_pose));
+ for (;;) {
if (should_quit)
break;
- while (inSocket.hasPendingDatagrams()) {
- QMutexLocker foo(&mutex);
- QByteArray datagram;
- datagram.resize(sizeof(newHeadPose));
- inSocket.readDatagram((char * ) newHeadPose, sizeof(double[6]));
+ QMutexLocker foo(&mutex);
+ while (sock.hasPendingDatagrams()) {
+ sock.readDatagram((char * ) last_recv_pose, sizeof(double[6]));
}
- usleep(10000);
- }
+ msleep(1);
+ }
}
void FTNoIR_Tracker::StartTracker(QFrame*)
{
- (void) inSocket.bind(QHostAddress::Any, (int) s.port, QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint);
+ (void) sock.bind(QHostAddress::Any, (int) s.port, QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint);
start();
}
diff --git a/ftnoir_tracker_udp/ftnoir_tracker_udp.h b/ftnoir_tracker_udp/ftnoir_tracker_udp.h
index 1d5de19b..a6f2e6d3 100644
--- a/ftnoir_tracker_udp/ftnoir_tracker_udp.h
+++ b/ftnoir_tracker_udp/ftnoir_tracker_udp.h
@@ -16,31 +16,28 @@ struct settings {
{}
};
-class FTNoIR_Tracker : public ITracker, public QThread
+class FTNoIR_Tracker : public ITracker, protected QThread
{
public:
FTNoIR_Tracker();
~FTNoIR_Tracker();
void StartTracker(QFrame *);
void GetHeadPoseData(double *data);
- volatile bool should_quit;
protected:
- void run(); // qthread override run method
+ void run() override;
private:
- QUdpSocket inSocket;
- QHostAddress destIP;
- QHostAddress srcIP;
- double newHeadPose[6];
+ QUdpSocket sock;
+ double last_recv_pose[6];
QMutex mutex;
settings s;
+ volatile bool should_quit;
};
class TrackerControls: public QWidget, public ITrackerDialog
{
Q_OBJECT
public:
-
- explicit TrackerControls();
+ TrackerControls();
void registerTracker(ITracker *) {}
void unRegisterTracker() {}
private:
@@ -59,4 +56,3 @@ public:
void getDescription(QString *strToBeFilled);
void getIcon(QIcon *icon);
};
-