annotate base/Thread.cpp @ 985:f073d924a7c3

Fix #1058 clicking row in Layer Edit dialog when colour 3d plot layer active jumps to wrong frame (was using sample rate where resolution intended)
author Chris Cannam
date Tue, 16 Sep 2014 10:29:19 +0100
parents e802e550a1f2
children 0e0947896fd3
rev   line source
Chris@109 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@109 2
Chris@109 3 /*
Chris@109 4 Sonic Visualiser
Chris@109 5 An audio file viewer and annotation editor.
Chris@109 6 Centre for Digital Music, Queen Mary, University of London.
Chris@109 7 This file copyright 2006 Chris Cannam.
Chris@109 8
Chris@109 9 This program is free software; you can redistribute it and/or
Chris@109 10 modify it under the terms of the GNU General Public License as
Chris@109 11 published by the Free Software Foundation; either version 2 of the
Chris@109 12 License, or (at your option) any later version. See the file
Chris@109 13 COPYING included with this distribution for more information.
Chris@109 14 */
Chris@109 15
Chris@109 16 #include "Thread.h"
Chris@109 17
Chris@109 18 #ifndef _WIN32
Chris@109 19 #include <pthread.h>
Chris@109 20 #endif
Chris@109 21
Chris@244 22 //#define DEBUG_MUTEX_LOCKER 1
Chris@244 23
Chris@244 24 #include <iostream>
Chris@244 25
Chris@109 26 Thread::Thread(Type type, QObject *parent) :
Chris@109 27 QThread(parent),
Chris@109 28 m_type(type)
Chris@109 29 {
Chris@109 30 setStackSize(512 * 1024);
Chris@109 31 }
Chris@109 32
Chris@109 33 void
Chris@109 34 Thread::start()
Chris@109 35 {
Chris@109 36 QThread::start();
Chris@109 37
Chris@109 38 #ifndef _WIN32
Chris@109 39 struct sched_param param;
Chris@109 40 ::memset(&param, 0, sizeof(param));
Chris@109 41
Chris@109 42 if (m_type == RTThread) {
Chris@109 43
Chris@109 44 param.sched_priority = 5;
Chris@109 45
Chris@109 46 if (::pthread_setschedparam(pthread_self(), SCHED_FIFO, &param)) {
Chris@109 47 ::perror("INFO: pthread_setschedparam to SCHED_FIFO failed");
Chris@109 48 }
Chris@109 49
Chris@109 50 } else {
Chris@109 51
Chris@109 52 if (::pthread_setschedparam(pthread_self(), SCHED_OTHER, &param)) {
Chris@109 53 ::perror("WARNING: pthread_setschedparam to SCHED_OTHER failed");
Chris@109 54 }
Chris@109 55 }
Chris@109 56
Chris@109 57 #endif
Chris@109 58 }
Chris@109 59
Chris@244 60 MutexLocker::MutexLocker(QMutex *mutex, const char *name) :
Chris@408 61 m_profiler(name, false),
Chris@244 62 m_printer(name),
Chris@244 63 m_locker(mutex)
Chris@244 64 {
Chris@244 65 #ifdef DEBUG_MUTEX_LOCKER
Chris@843 66 cerr << "... locked mutex " << mutex << endl;
Chris@244 67 #endif
Chris@408 68 m_profiler.end();
Chris@244 69 }
Chris@244 70
Chris@244 71 MutexLocker::~MutexLocker()
Chris@244 72 {
Chris@244 73 }
Chris@244 74
Chris@244 75 MutexLocker::Printer::Printer(const char *name) :
Chris@244 76 m_name(name)
Chris@244 77 {
Chris@244 78 #ifdef DEBUG_MUTEX_LOCKER
Chris@843 79 cerr << "MutexLocker: Locking \"" << m_name << "\" in "
Chris@843 80 << (void *)QThread::currentThreadId() << endl;
Chris@244 81 #endif
Chris@244 82 }
Chris@244 83
Chris@244 84 MutexLocker::Printer::~Printer()
Chris@244 85 {
Chris@244 86 #ifdef DEBUG_MUTEX_LOCKER
Chris@843 87 cerr << "MutexLocker: Unlocking \"" << m_name
Chris@843 88 << "\" in " << (void *)QThread::currentThreadId() << endl;
Chris@244 89 #endif
Chris@244 90 }
Chris@244 91