Remove CSamplesConcurrent from samples_blackmisc

This commit is contained in:
Roland Winklmeier
2015-05-30 15:04:57 +02:00
parent eb93317190
commit d3de687db2
3 changed files with 0 additions and 184 deletions

View File

@@ -14,7 +14,6 @@
#include "samplesjson.h"
#include "samplesperformance.h"
#include "samplesalgorithm.h"
#include "samplesconcurrent.h"
#include "blackmisc/blackmiscfreefunctions.h"
#include "blackmisc/pq/pq.h"
@@ -46,7 +45,6 @@ int main(int argc, char *argv[])
qtout << "6c .. 25/20 Performance impl. type" << endl;
qtout << "6d .. 40/20 Interpolator scenario" << endl;
qtout << "7 .. Algorithms" << endl;
qtout << "8 .. Concurrent (thread)" << endl;
qtout << "-----" << endl;
qtout << "x .. Bye" << endl;
QString s = qtin.readLine().toLower().trimmed();
@@ -60,7 +58,6 @@ int main(int argc, char *argv[])
else if (s.startsWith("6c")) { CSamplesPerformance::samplesImplementationType(qtout, 25, 20); }
else if (s.startsWith("6d")) { CSamplesPerformance::interpolatorScenario(qtout, 40, 20); }
else if (s.startsWith("7")) { CSamplesAlgorithm::samples(); }
else if (s.startsWith("8")) { CSamplesConcurrent::samples(s, qtout, qtin); }
else if (s.startsWith("x")) { break; }
}
while (true);

View File

@@ -1,103 +0,0 @@
/* Copyright (C) 2015
* swift Project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
#include "samplesconcurrent.h"
#include "blackmisc/algorithm.h"
#include <QDebug>
#include <QGuiApplication>
#include <QtConcurrent/QtConcurrent>
#include <QString>
using namespace BlackMisc;
namespace BlackMiscTest
{
int CSamplesConcurrent::samples(const QString &type, QTextStream &out, QTextStream &in)
{
Q_UNUSED(in);
Q_UNUSED(type);
out << "Main thread id: " << QThread::currentThreadId() << endl;
CThreadOutput b1("b1", QGuiApplication::instance());
b1.start();
CThreadOutput b2("b2", QGuiApplication::instance());
b2.start();
CThreadOutput b3("b3", QGuiApplication::instance());
b3.start();
QThread::msleep(10 * 1000);
b1.stop();
b2.stop();
b3.stop();
QThread::msleep(1 * 1000); // allow to stop
out << "Main thread id: " << QThread::currentThreadId() << endl;
CConcurrentOutput c1("c1");
QtConcurrent::run(&c1, &CConcurrentOutput::doWork);
CConcurrentOutput c2("c2");
QtConcurrent::run(&c2, &CConcurrentOutput::doWork);
CConcurrentOutput c3("c3");
QtConcurrent::run(&c3, &CConcurrentOutput::doWork);
QThread::msleep(10 * 1000);
c1.stop();
c2.stop();
// stop 2, but then wait and see whats happening
out << "stopped c1, c2" << endl;
QThread::msleep(5 * 1000);
out << "stopped c3" << endl;
c3.stop();
QThread::msleep(1 * 1000); // allow to stop
return 0;
}
CThreadOutput::CThreadOutput(const QString &name, QObject *parent) :
CContinuousWorker(parent, name)
{ }
void CThreadOutput::doWork()
{
QTextStream out(stdout);
while (m_run)
{
out << this->objectName() << " worker id: " << QThread::currentThreadId() << endl;
QThread::msleep(1000);
}
}
void CThreadOutput::stop()
{
m_run = false;
}
void CThreadOutput::initialize()
{
this->doWork();
}
CConcurrentOutput::CConcurrentOutput(const QString &name, QObject *parent) :
QObject(parent), m_name(name)
{ }
void CConcurrentOutput::stop()
{
m_run = false;
}
void CConcurrentOutput::doWork()
{
QTextStream out(stdout);
while (m_run)
{
out << m_name << " worker id: " << QThread::currentThreadId() << endl;
QThread::msleep(1000);
}
}
} // namespace

View File

@@ -1,78 +0,0 @@
/* Copyright (C) 2015
* swift Project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
//! \file
#ifndef BLACKMISCTEST_SAMPLESCONCURRENT_H
#define BLACKMISCTEST_SAMPLESCONCURRENT_H
#include "blackmisc/worker.h"
#include <QTextStream>
#include <atomic>
namespace BlackMiscTest
{
//! Samples for metadata
class CSamplesConcurrent
{
public:
//! Run the samples
static int samples(const QString &type, QTextStream &out, QTextStream &in);
};
//! Doing some work
class CThreadOutput : public BlackMisc::CContinuousWorker
{
Q_OBJECT
public:
//! Constructor
CThreadOutput(const QString &name, QObject *parent = nullptr);
//! Working task
void doWork();
//! Stop
void stop();
protected slots:
//! \copydoc CContinuousWorker::initialize
virtual void initialize() override;
private:
std::atomic<bool> m_run { true };
};
//! Doing some work
class CConcurrentOutput : public QObject
{
Q_OBJECT
public:
//! Constructor
CConcurrentOutput(const QString &name, QObject *parent = nullptr);
//! Stop
void stop();
public slots:
//! Working task
void doWork();
private:
std::atomic<bool> m_run { true };
QString m_name;
};
} // namespace
#endif