Mercurial > hg > easaier-soundaccess
comparison base/Thread.cpp @ 0:fc9323a41f5a
start base : Sonic Visualiser sv1-1.0rc1
author | lbajardsilogic |
---|---|
date | Fri, 11 May 2007 09:08:14 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:fc9323a41f5a |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 /* | |
4 Sonic Visualiser | |
5 An audio file viewer and annotation editor. | |
6 Centre for Digital Music, Queen Mary, University of London. | |
7 This file copyright 2006 Chris Cannam. | |
8 | |
9 This program is free software; you can redistribute it and/or | |
10 modify it under the terms of the GNU General Public License as | |
11 published by the Free Software Foundation; either version 2 of the | |
12 License, or (at your option) any later version. See the file | |
13 COPYING included with this distribution for more information. | |
14 */ | |
15 | |
16 #include "Thread.h" | |
17 | |
18 #ifndef _WIN32 | |
19 #include <pthread.h> | |
20 #endif | |
21 | |
22 //#define DEBUG_MUTEX_LOCKER 1 | |
23 | |
24 #include <iostream> | |
25 | |
26 Thread::Thread(Type type, QObject *parent) : | |
27 QThread(parent), | |
28 m_type(type) | |
29 { | |
30 setStackSize(512 * 1024); | |
31 } | |
32 | |
33 void | |
34 Thread::start() | |
35 { | |
36 QThread::start(); | |
37 | |
38 #ifndef _WIN32 | |
39 struct sched_param param; | |
40 ::memset(¶m, 0, sizeof(param)); | |
41 | |
42 if (m_type == RTThread) { | |
43 | |
44 param.sched_priority = 5; | |
45 | |
46 if (::pthread_setschedparam(pthread_self(), SCHED_FIFO, ¶m)) { | |
47 ::perror("INFO: pthread_setschedparam to SCHED_FIFO failed"); | |
48 } | |
49 | |
50 } else { | |
51 | |
52 if (::pthread_setschedparam(pthread_self(), SCHED_OTHER, ¶m)) { | |
53 ::perror("WARNING: pthread_setschedparam to SCHED_OTHER failed"); | |
54 } | |
55 } | |
56 | |
57 #endif | |
58 } | |
59 | |
60 MutexLocker::MutexLocker(QMutex *mutex, const char *name) : | |
61 m_printer(name), | |
62 m_locker(mutex) | |
63 { | |
64 #ifdef DEBUG_MUTEX_LOCKER | |
65 std::cerr << "... locked mutex " << mutex << std::endl; | |
66 #endif | |
67 } | |
68 | |
69 MutexLocker::~MutexLocker() | |
70 { | |
71 } | |
72 | |
73 MutexLocker::Printer::Printer(const char *name) : | |
74 m_name(name) | |
75 { | |
76 #ifdef DEBUG_MUTEX_LOCKER | |
77 std::cerr << "MutexLocker: Locking \"" << m_name << "\" in " | |
78 << (void *)QThread::currentThreadId() << std::endl; | |
79 #endif | |
80 } | |
81 | |
82 MutexLocker::Printer::~Printer() | |
83 { | |
84 #ifdef DEBUG_MUTEX_LOCKER | |
85 std::cerr << "MutexLocker: Unlocking \"" << m_name | |
86 << "\" in " << (void *)QThread::currentThreadId() << std::endl; | |
87 #endif | |
88 } | |
89 |