From d3de687db2662f6d97fa05416b9dadb21e979905 Mon Sep 17 00:00:00 2001 From: Roland Winklmeier Date: Sat, 30 May 2015 15:04:57 +0200 Subject: [PATCH] Remove CSamplesConcurrent from samples_blackmisc --- samples/blackmisc/main.cpp | 3 - samples/blackmisc/samplesconcurrent.cpp | 103 ------------------------ samples/blackmisc/samplesconcurrent.h | 78 ------------------ 3 files changed, 184 deletions(-) delete mode 100644 samples/blackmisc/samplesconcurrent.cpp delete mode 100644 samples/blackmisc/samplesconcurrent.h diff --git a/samples/blackmisc/main.cpp b/samples/blackmisc/main.cpp index dc00d9cf8..3d7d3d2a2 100644 --- a/samples/blackmisc/main.cpp +++ b/samples/blackmisc/main.cpp @@ -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); diff --git a/samples/blackmisc/samplesconcurrent.cpp b/samples/blackmisc/samplesconcurrent.cpp deleted file mode 100644 index f374e737a..000000000 --- a/samples/blackmisc/samplesconcurrent.cpp +++ /dev/null @@ -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 -#include -#include -#include - -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 diff --git a/samples/blackmisc/samplesconcurrent.h b/samples/blackmisc/samplesconcurrent.h deleted file mode 100644 index b528ddd83..000000000 --- a/samples/blackmisc/samplesconcurrent.h +++ /dev/null @@ -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 -#include - -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 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 m_run { true }; - QString m_name; - }; - - - -} // namespace - -#endif