svcore  1.9
Thread.h
Go to the documentation of this file.
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 #ifndef _THREAD_H_
00017 #define _THREAD_H_
00018 
00019 #include <QThread>
00020 #include <QMutexLocker>
00021 
00022 #include "Profiler.h"
00023 
00024 class Thread : public QThread
00025 {
00026 Q_OBJECT
00027 
00028 public:
00029     enum Type { RTThread, NonRTThread };
00030 
00031     Thread(Type type = NonRTThread, QObject *parent = 0);
00032 
00033 public slots:
00034     void start();
00035 
00036 protected:
00037     virtual void run() = 0;
00038 
00039 private:    
00040     Type m_type;
00041 };
00042 
00043 class MutexLocker
00044 {
00045 public:
00046     MutexLocker(QMutex *mutex, const char *name);
00047     ~MutexLocker();
00048 
00049 private:
00050     class Printer {
00051     public:
00052         Printer(const char *name);
00053         ~Printer();
00054 
00055     private:
00056         const char *m_name;
00057     };
00058 
00059     Profiler m_profiler;
00060     Printer m_printer;
00061     QMutexLocker m_locker;
00062 };
00063 
00064 #endif