wait on broadcastThread before destroying AvatarMixer, closes #2499

This commit is contained in:
Stephen Birarda 2014-03-26 11:53:57 -07:00
parent 4ac487f832
commit 962c7350f3
2 changed files with 12 additions and 7 deletions

View file

@ -32,6 +32,7 @@ const unsigned int AVATAR_DATA_SEND_INTERVAL_MSECS = (1.0f / 60.0f) * 1000;
AvatarMixer::AvatarMixer(const QByteArray& packet) : AvatarMixer::AvatarMixer(const QByteArray& packet) :
ThreadedAssignment(packet), ThreadedAssignment(packet),
_broadcastThread(),
_lastFrameTimestamp(QDateTime::currentMSecsSinceEpoch()), _lastFrameTimestamp(QDateTime::currentMSecsSinceEpoch()),
_trailingSleepRatio(1.0f), _trailingSleepRatio(1.0f),
_performanceThrottlingRatio(0.0f), _performanceThrottlingRatio(0.0f),
@ -44,6 +45,11 @@ AvatarMixer::AvatarMixer(const QByteArray& packet) :
connect(NodeList::getInstance(), &NodeList::nodeKilled, this, &AvatarMixer::nodeKilled); connect(NodeList::getInstance(), &NodeList::nodeKilled, this, &AvatarMixer::nodeKilled);
} }
AvatarMixer::~AvatarMixer() {
_broadcastThread.quit();
_broadcastThread.wait();
}
void attachAvatarDataToNode(Node* newNode) { void attachAvatarDataToNode(Node* newNode) {
if (!newNode->getLinkedData()) { if (!newNode->getLinkedData()) {
newNode->setLinkedData(new AvatarMixerClientData()); newNode->setLinkedData(new AvatarMixerClientData());
@ -309,18 +315,15 @@ void AvatarMixer::run() {
nodeList->linkedDataCreateCallback = attachAvatarDataToNode; nodeList->linkedDataCreateCallback = attachAvatarDataToNode;
// create a thead for broadcast of avatar data
QThread* broadcastThread = new QThread(this);
// setup the timer that will be fired on the broadcast thread // setup the timer that will be fired on the broadcast thread
QTimer* broadcastTimer = new QTimer(); QTimer* broadcastTimer = new QTimer();
broadcastTimer->setInterval(AVATAR_DATA_SEND_INTERVAL_MSECS); broadcastTimer->setInterval(AVATAR_DATA_SEND_INTERVAL_MSECS);
broadcastTimer->moveToThread(broadcastThread); broadcastTimer->moveToThread(&_broadcastThread);
// connect appropriate signals and slots // connect appropriate signals and slots
connect(broadcastTimer, &QTimer::timeout, this, &AvatarMixer::broadcastAvatarData, Qt::DirectConnection); connect(broadcastTimer, &QTimer::timeout, this, &AvatarMixer::broadcastAvatarData, Qt::DirectConnection);
connect(broadcastThread, SIGNAL(started()), broadcastTimer, SLOT(start())); connect(&_broadcastThread, SIGNAL(started()), broadcastTimer, SLOT(start()));
// start the broadcastThread // start the broadcastThread
broadcastThread->start(); _broadcastThread.start();
} }

View file

@ -15,7 +15,7 @@
class AvatarMixer : public ThreadedAssignment { class AvatarMixer : public ThreadedAssignment {
public: public:
AvatarMixer(const QByteArray& packet); AvatarMixer(const QByteArray& packet);
~AvatarMixer();
public slots: public slots:
/// runs the avatar mixer /// runs the avatar mixer
void run(); void run();
@ -30,6 +30,8 @@ public slots:
private: private:
void broadcastAvatarData(); void broadcastAvatarData();
QThread _broadcastThread;
quint64 _lastFrameTimestamp; quint64 _lastFrameTimestamp;
float _trailingSleepRatio; float _trailingSleepRatio;