From 7148a0b5c907d7f8b0512b594b9d84c4ff089ee2 Mon Sep 17 00:00:00 2001 From: Thorvald Natvig Date: Mon, 16 Feb 2009 14:25:12 +0000 Subject: Add a thread count test git-svn-id: https://mumble.svn.sourceforge.net/svnroot/mumble/trunk@1541 05730e5d-ab1b-0410-a4ac-84af385074fa --- src/murmur/UnixMurmur.cpp | 62 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) (limited to 'src/murmur/UnixMurmur.cpp') diff --git a/src/murmur/UnixMurmur.cpp b/src/murmur/UnixMurmur.cpp index b4857e384..ec4c32a7a 100644 --- a/src/murmur/UnixMurmur.cpp +++ b/src/murmur/UnixMurmur.cpp @@ -30,9 +30,71 @@ #include +#include "murmur_pch.h" #include "UnixMurmur.h" #include "Meta.h" +QMutex *LimitTest::qm; +QWaitCondition *LimitTest::qw; + +LimitTest::LimitTest() : QThread() { +} + +void LimitTest::run() { + qm->lock(); + qw->wait(qm); + qm->unlock(); +} + +void LimitTest::testLimits(QCoreApplication &a) { + QAbstractEventDispatcher *ed = QAbstractEventDispatcher::instance(); + if (QLatin1String(ed->metaObject()->className()) != QLatin1String("QEventDispatcherGlib")) + qWarning("Not running with glib. While you may be able to open more descriptors, sockets above %d will not work", FD_SETSIZE); + qWarning("Running descriptor test."); + int count; + QList ql; + for (count=0;count < 524288; ++count) { + QFile *qf = new QFile(a.applicationFilePath()); + if (qf->open(QIODevice::ReadOnly)) + ql << qf; + else + break; + if ((count & 511) == 0) + qWarning("%d descriptors...", count); + } + foreach(QFile *qf, ql) + delete qf; + ql.clear(); + qCritical("Managed to open %d descriptors", count); + + qm = new QMutex(); + qw = new QWaitCondition(); + + int fdcount = count / 2; + + QList qtl; + for (count=0;count < fdcount; ++count) { + QThread *t = new LimitTest(); + qtl << t; + t->start(); + if (! t->isRunning()) + break; + if ((count & 511) == 0) + qWarning("%d threads...", count); + } + sleep(1); + qm->lock(); + qw->wakeAll(); + qm->unlock(); + foreach(QThread *qt, qtl) { + if (! qt->wait(1000)) { + qWarning("Thread failed to terminate..."); + qt->terminate(); + } + } + qFatal("Managed to spawn %d threads", count); +} + extern QFile *qfLog; int UnixMurmur::iHupFd[2]; -- cgit v1.2.3