Commit 80fd123b authored by Thomas Eschenbacher's avatar Thomas Eschenbacher
Browse files

use QThread::isInterruptionRequested() and requestInterruption()

parent cf1842b1
......@@ -106,14 +106,14 @@ void Kwave::FilterPlugin::run(QStringList params)
// switch to interactive mode in pre-listen mode
Kwave::StreamObject::setInteractive(m_listen);
Kwave::SampleSource *filter = createFilter(tracks.count());
Q_ASSERT(filter);
// create all objects
Kwave::MultiTrackReader source(
(m_listen) ? Kwave::FullSnapshot : Kwave::SinglePassForward,
signalManager(), tracks, first, last);
Kwave::SampleSource *filter = createFilter(tracks.count());
Q_ASSERT(filter);
if (m_listen) {
// pre-listen mode
Q_ASSERT(m_sink);
......
......@@ -381,7 +381,7 @@ void Kwave::PlaybackController::startDevicePlayBack()
//***************************************************************************
void Kwave::PlaybackController::stopDevicePlayBack()
{
m_thread.cancel();
m_thread.requestInterruption();
if (!m_thread.isRunning()) {
qDebug("PlaybackController::stopDevicePlayBack() - not running");
emit sigDevicePlaybackDone();
......@@ -444,7 +444,7 @@ void Kwave::PlaybackController::run_wrapper(const QVariant &params)
// samples (this happens when resuming after a pause)
if (pos > first) input.skip(pos - first);
while ((pos++ <= last) && !m_thread.shouldStop()) {
while ((pos++ <= last) && !m_thread.isInterruptionRequested()) {
unsigned int x;
unsigned int y;
bool seek_again = false;
......@@ -512,7 +512,7 @@ void Kwave::PlaybackController::run_wrapper(const QVariant &params)
result = m_device->write(out_samples);
}
if (result) {
m_thread.cancel();
m_thread.requestInterruption();
pos = last;
}
......@@ -528,12 +528,12 @@ void Kwave::PlaybackController::run_wrapper(const QVariant &params)
// maybe we loop. in this case the playback starts
// again from the left marker
if (m_loop_mode && !m_thread.shouldStop()) {
if (m_loop_mode && !m_thread.isInterruptionRequested()) {
input.reset();
pos = startPos();
}
} while (m_loop_mode && !m_thread.shouldStop());
} while (m_loop_mode && !m_thread.isInterruptionRequested());
// playback is done
emit sigDevicePlaybackDone();
......
......@@ -52,7 +52,6 @@ Kwave::WorkerThread::WorkerThread(Kwave::Runnable *runnable, QVariant params)
m_runnable(runnable),
m_params(params),
m_lock(), m_lock_sighup(),
m_should_stop(0),
m_tid(pthread_self()),
m_owner_tid(pthread_self())
{
......@@ -87,11 +86,6 @@ Kwave::WorkerThread::~WorkerThread()
//***************************************************************************
void Kwave::WorkerThread::start()
{
QMutexLocker lock(&m_lock);
// reset the "should stop" command flag
m_should_stop = 0;
QThread::start();
}
......@@ -104,7 +98,7 @@ int Kwave::WorkerThread::stop(unsigned int timeout)
if (timeout < 1000) timeout = 1000;
// set the "should stop" flag
m_should_stop = 1;
requestInterruption();
// send one SIGHUP in advance
{
......@@ -171,17 +165,5 @@ void Kwave::WorkerThread::run()
}
}
//***************************************************************************
void Kwave::WorkerThread::cancel()
{
m_should_stop = 1;
}
//***************************************************************************
bool Kwave::WorkerThread::shouldStop()
{
return (m_should_stop);
}
//***************************************************************************
//***************************************************************************
......@@ -21,7 +21,6 @@
#include "config.h"
#include <pthread.h>
#include <QAtomicInt>
#include <QtGlobal>
#include <QMutex>
#include <QObject>
......@@ -61,19 +60,6 @@ namespace Kwave
*/
virtual void run() Q_DECL_OVERRIDE;
/**
* Sets an internal flag that signals the worker thread to cancel,
* so that the next call to "shouldStop()" returns true.
*/
virtual void cancel();
/**
* Returns true if the thread should stop. Should be polled
* by the thread's run() function to wait for a termination
* signal.
*/
bool shouldStop();
private:
/** pointer to the object that has a run() function */
......@@ -88,9 +74,6 @@ namespace Kwave
/** Mutex for protecting SIGHUP <-> thread exit */
QMutex m_lock_sighup;
/** set to 1 to signal the thread that it should stop */
QAtomicInt m_should_stop;
/**
* POSIX compatible thread ID of the worker thread.
* only needed and only valid while the thread is running.
......
......@@ -411,7 +411,7 @@ bool Kwave::PlayBackPulseAudio::connectToServer()
void Kwave::PlayBackPulseAudio::disconnectFromServer()
{
// stop the main loop
m_mainloop_thread.cancel();
m_mainloop_thread.requestInterruption();
if (m_pa_mainloop) {
m_mainloop_lock.lock();
pa_mainloop_quit(m_pa_mainloop, 0);
......
......@@ -982,7 +982,7 @@ void Kwave::RecordPulseAudio::disconnectFromServer()
close();
// stop the main loop
m_mainloop_thread.cancel();
m_mainloop_thread.isInterruptionRequested();
if (m_pa_mainloop) {
m_mainloop_lock.lock();
pa_mainloop_quit(m_pa_mainloop, 0);
......
......@@ -124,7 +124,7 @@ void Kwave::RecordThread::run()
bool interrupted = false;
// read data until we receive a close signal
while (!shouldStop() && !interrupted) {
while (!isInterruptionRequested() && !interrupted) {
// dequeue a buffer from the "empty" queue
QByteArray buffer;
......@@ -150,7 +150,7 @@ void Kwave::RecordThread::run()
// read into the current buffer
unsigned int offset = 0;
while (len && !interrupted && !shouldStop()) {
while (len && !interrupted && !isInterruptionRequested()) {
// read raw data from the record device
result = (m_device) ?
m_device->read(buffer, offset) : -EBADF;
......@@ -200,7 +200,7 @@ void Kwave::RecordThread::run()
// do not evaluate the result of the last operation if there
// was the external request to stop
if (shouldStop() || (interrupted && (result > 0)))
if (isInterruptionRequested() || (interrupted && (result > 0)))
result = 0;
if (result) emit stopped(result);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment