some QThread cleanup and fix in Socket

This commit is contained in:
Stephen Birarda 2015-08-31 11:30:31 -07:00
parent fa0abe2972
commit de2bfd0d0d
7 changed files with 23 additions and 12 deletions

View file

@ -457,8 +457,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
audioThread->start();
QThread* assetThread = new QThread();
QThread* assetThread = new QThread;
assetThread->setObjectName("Asset Thread");
auto assetClient = DependencyManager::get<AssetClient>();
@ -467,7 +466,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
assetThread->start();
const DomainHandler& domainHandler = nodeList->getDomainHandler();
connect(&domainHandler, SIGNAL(hostnameChanged(const QString&)), SLOT(domainChanged(const QString&)));
@ -878,6 +876,12 @@ Application::~Application() {
DependencyManager::destroy<GeometryCache>();
DependencyManager::destroy<ScriptCache>();
DependencyManager::destroy<SoundCache>();
// cleanup the AssetClient thread
QThread* assetThread = DependencyManager::get<AssetClient>()->thread();
DependencyManager::destroy<AssetClient>();
assetThread->quit();
assetThread->wait();
QThread* nodeThread = DependencyManager::get<NodeList>()->thread();
@ -887,7 +891,7 @@ Application::~Application() {
// ask the node thread to quit and wait until it is done
nodeThread->quit();
nodeThread->wait();
Leapmotion::destroy();
RealSense::destroy();
ConnexionClient::getInstance().destroy();

View file

@ -24,6 +24,11 @@ MessageID AssetClient::_currentID = 0;
AssetClient::AssetClient() {
setCustomDeleter([](Dependency* dependency){
static_cast<AssetClient*>(dependency)->deleteLater();
});
auto& packetReceiver = DependencyManager::get<NodeList>()->getPacketReceiver();
packetReceiver.registerListener(PacketType::AssetGetInfoReply, this, "handleAssetGetInfoReply");
packetReceiver.registerMessageListener(PacketType::AssetGetReply, this, "handleAssetGetReply");

View file

@ -66,7 +66,7 @@ LimitedNodeList::LimitedNodeList(unsigned short socketListenPort, unsigned short
firstCall = false;
}
qRegisterMetaType<ConnectionStep>("ConnectionStep");
_nodeSocket.bind(QHostAddress::AnyIPv4, socketListenPort);

View file

@ -53,7 +53,7 @@ std::unique_ptr<SendQueue> SendQueue::create(Socket* socket, HifiSockAddr destin
Q_ASSERT_X(socket, "SendQueue::create", "Must be called with a valid Socket*");
// Setup queue private thread
QThread* thread = new QThread();
QThread* thread = new QThread;
thread->setObjectName("Networking: SendQueue " + destination.objectName()); // Name thread for easier debug
connect(thread, &QThread::started, queue.get(), &SendQueue::run);

View file

@ -30,10 +30,10 @@ Socket::Socket(QObject* parent) :
connect(&_udpSocket, &QUdpSocket::readyRead, this, &Socket::readPendingDatagrams);
// make sure our synchronization method is called every SYN interval
connect(&_synTimer, &QTimer::timeout, this, &Socket::rateControlSync);
connect(_synTimer, &QTimer::timeout, this, &Socket::rateControlSync);
// start our timer for the synchronization time interval
_synTimer.start(_synInterval);
_synTimer->start(_synInterval);
}
void Socket::rebind() {
@ -262,10 +262,10 @@ void Socket::rateControlSync() {
connection.second->sync();
}
if (_synTimer.interval() != _synInterval) {
if (_synTimer->interval() != _synInterval) {
// if the _synTimer interval doesn't match the current _synInterval (changes when the CC factory is changed)
// then restart it now with the right interval
_synTimer.start(_synInterval);
_synTimer->start(_synInterval);
}
}

View file

@ -43,6 +43,7 @@ class Socket : public QObject {
Q_OBJECT
public:
Socket(QObject* object = 0);
~Socket();
quint16 localPort() const { return _udpSocket.localPort(); }
@ -97,7 +98,7 @@ private:
QMutex _connectionsMutex; // guards concurrent access to connections hashs
int _synInterval = 10; // 10ms
QTimer _synTimer;
QTimer* _synTimer;
std::unique_ptr<CongestionControlVirtualFactory> _ccFactory { new CongestionControlFactory<DefaultCC>() };
};

View file

@ -19,6 +19,7 @@ GenericThread::GenericThread(QObject* parent) :
_stopThread(false),
_isThreaded(false) // assume non-threaded, must call initialize()
{
}
GenericThread::~GenericThread() {
@ -32,7 +33,7 @@ void GenericThread::initialize(bool isThreaded, QThread::Priority priority) {
_isThreaded = isThreaded;
if (_isThreaded) {
_thread = new QThread(this);
// match the thread name to our object name
_thread->setObjectName(objectName());