00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "Thread.h"
00017
00018 #ifndef _WIN32
00019 #include <pthread.h>
00020 #endif
00021
00022
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_printer(name),
00062 m_locker(mutex)
00063 {
00064 #ifdef DEBUG_MUTEX_LOCKER
00065 std::cerr << "... locked mutex " << mutex << std::endl;
00066 #endif
00067 }
00068
00069 MutexLocker::~MutexLocker()
00070 {
00071 }
00072
00073 MutexLocker::Printer::Printer(const char *name) :
00074 m_name(name)
00075 {
00076 #ifdef DEBUG_MUTEX_LOCKER
00077 std::cerr << "MutexLocker: Locking \"" << m_name << "\" in "
00078 << (void *)QThread::currentThreadId() << std::endl;
00079 #endif
00080 }
00081
00082 MutexLocker::Printer::~Printer()
00083 {
00084 #ifdef DEBUG_MUTEX_LOCKER
00085 std::cerr << "MutexLocker: Unlocking \"" << m_name
00086 << "\" in " << (void *)QThread::currentThreadId() << std::endl;
00087 #endif
00088 }
00089