From 52d2fd3bf8e3241c9a671a66daaf3150c6d7ed5b Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 22 Sep 2014 11:50:27 +0200 Subject: udp: cleanup, reduce mtx contention --- ftnoir_tracker_udp/ftnoir_tracker_udp.cpp | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) (limited to 'ftnoir_tracker_udp/ftnoir_tracker_udp.cpp') 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(); } -- cgit v1.2.3