svcore
1.9
|
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ 00002 00003 /* 00004 Sonic Visualiser 00005 An audio file viewer and annotation editor. 00006 Centre for Digital Music, Queen Mary, University of London. 00007 This file copyright 2006 Chris Cannam. 00008 00009 This program is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU General Public License as 00011 published by the Free Software Foundation; either version 2 of the 00012 License, or (at your option) any later version. See the file 00013 COPYING included with this distribution for more information. 00014 */ 00015 00016 #include "Thread.h" 00017 00018 #ifndef _WIN32 00019 #include <pthread.h> 00020 #endif 00021 00022 //#define DEBUG_MUTEX_LOCKER 1 00023 00024 #include <iostream> 00025 00026 Thread::Thread(Type type, QObject *parent) : 00027 QThread(parent), 00028 m_type(type) 00029 { 00030 setStackSize(512 * 1024); 00031 } 00032 00033 void 00034 Thread::start() 00035 { 00036 QThread::start(); 00037 00038 #ifndef _WIN32 00039 struct sched_param param; 00040 ::memset(¶m, 0, sizeof(param)); 00041 00042 if (m_type == RTThread) { 00043 00044 param.sched_priority = 5; 00045 00046 if (::pthread_setschedparam(pthread_self(), SCHED_FIFO, ¶m)) { 00047 ::perror("INFO: pthread_setschedparam to SCHED_FIFO failed"); 00048 } 00049 00050 } else { 00051 00052 if (::pthread_setschedparam(pthread_self(), SCHED_OTHER, ¶m)) { 00053 ::perror("WARNING: pthread_setschedparam to SCHED_OTHER failed"); 00054 } 00055 } 00056 00057 #endif 00058 } 00059 00060 MutexLocker::MutexLocker(QMutex *mutex, const char *name) : 00061 m_profiler(name, false), 00062 m_printer(name), 00063 m_locker(mutex) 00064 { 00065 #ifdef DEBUG_MUTEX_LOCKER 00066 cerr << "... locked mutex " << mutex << endl; 00067 #endif 00068 m_profiler.end(); 00069 } 00070 00071 MutexLocker::~MutexLocker() 00072 { 00073 } 00074 00075 MutexLocker::Printer::Printer(const char *name) : 00076 m_name(name) 00077 { 00078 #ifdef DEBUG_MUTEX_LOCKER 00079 cerr << "MutexLocker: Locking \"" << m_name << "\" in " 00080 << (void *)QThread::currentThreadId() << endl; 00081 #endif 00082 } 00083 00084 MutexLocker::Printer::~Printer() 00085 { 00086 #ifdef DEBUG_MUTEX_LOCKER 00087 cerr << "MutexLocker: Unlocking \"" << m_name 00088 << "\" in " << (void *)QThread::currentThreadId() << endl; 00089 #endif 00090 } 00091