annotate base/Thread.cpp @ 286:20097c32d15d

* Better abbreviation modes for layer names in pane (and input model combo of plugin parameter dialog) * Avoid crash when loading SV file containing model derived from nonexistent model (shouldn't happen of course, but see bug #1771769) * Remember last-used input model in plugin parameter dialog * Don't override a layer colour loaded from a session file with the generated default colour when attaching it to a view
author Chris Cannam
date Fri, 10 Aug 2007 16:36:50 +0000
parents 85bf384db35f
children 115f60df1e4d
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@244 61 m_printer(name),
Chris@244 62 m_locker(mutex)
Chris@244 63 {
Chris@244 64 #ifdef DEBUG_MUTEX_LOCKER
Chris@244 65 std::cerr << "... locked mutex " << mutex << std::endl;
Chris@244 66 #endif
Chris@244 67 }
Chris@244 68
Chris@244 69 MutexLocker::~MutexLocker()
Chris@244 70 {
Chris@244 71 }
Chris@244 72
Chris@244 73 MutexLocker::Printer::Printer(const char *name) :
Chris@244 74 m_name(name)
Chris@244 75 {
Chris@244 76 #ifdef DEBUG_MUTEX_LOCKER
Chris@244 77 std::cerr << "MutexLocker: Locking \"" << m_name << "\" in "
Chris@244 78 << (void *)QThread::currentThreadId() << std::endl;
Chris@244 79 #endif
Chris@244 80 }
Chris@244 81
Chris@244 82 MutexLocker::Printer::~Printer()
Chris@244 83 {
Chris@244 84 #ifdef DEBUG_MUTEX_LOCKER
Chris@244 85 std::cerr << "MutexLocker: Unlocking \"" << m_name
Chris@244 86 << "\" in " << (void *)QThread::currentThreadId() << std::endl;
Chris@244 87 #endif
Chris@244 88 }
Chris@244 89