~ubuntu-branches/ubuntu/utopic/lmms/utopic-proposed

« back to all changes in this revision

Viewing changes to include/MixerWorkerThread.h

  • Committer: Package Import Robot
  • Author(s): Israel Dahl
  • Date: 2014-04-30 18:49:37 UTC
  • mfrom: (1.1.15)
  • Revision ID: package-import@ubuntu.com-20140430184937-hozuuxonlbshciya
Tags: 1.0.1-src-0ubuntu1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * MixerWorkerThread.h - declaration of class MixerWorkerThread
3
 
 *
4
 
 * Copyright (c) 2009-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
5
 
 *
6
 
 * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
7
 
 *
8
 
 * This program is free software; you can redistribute it and/or
9
 
 * modify it under the terms of the GNU General Public
10
 
 * License as published by the Free Software Foundation; either
11
 
 * version 2 of the License, or (at your option) any later version.
12
 
 *
13
 
 * This program is distributed in the hope that it will be useful,
14
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 
 * General Public License for more details.
17
 
 *
18
 
 * You should have received a copy of the GNU General Public
19
 
 * License along with this program (see COPYING); if not, write to the
20
 
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21
 
 * Boston, MA 02110-1301 USA.
22
 
 *
23
 
 */
24
 
 
25
 
#ifndef _MIXER_WORKER_THREAD_H
26
 
#define _MIXER_WORKER_THREAD_H
27
 
 
28
 
#include <QtCore/QAtomicPointer>
29
 
#include <QtCore/QThread>
30
 
 
31
 
#include "ThreadableJob.h"
32
 
#include "Mixer.h"
33
 
 
34
 
 
35
 
class MixerWorkerThread : public QThread
36
 
{
37
 
public:
38
 
        // internal representation of the job queue - all functions are thread-safe
39
 
        class JobQueue
40
 
        {
41
 
        public:
42
 
                enum OperationMode
43
 
                {
44
 
                        Static, // no jobs added while processing queue
45
 
                        Dynamic // jobs can be added while processing queue
46
 
                } ;
47
 
 
48
 
                JobQueue() :
49
 
                        m_items(),
50
 
                        m_queueSize( 0 ),
51
 
                        m_itemsDone( 0 ),
52
 
                        m_opMode( Static )
53
 
                {
54
 
                }
55
 
 
56
 
                void reset( OperationMode _opMode );
57
 
 
58
 
                void addJob( ThreadableJob * _job );
59
 
 
60
 
                void run( sampleFrame * _buffer );
61
 
                void wait();
62
 
 
63
 
        private:
64
 
#define JOB_QUEUE_SIZE 1024
65
 
                QAtomicPointer<ThreadableJob> m_items[JOB_QUEUE_SIZE];
66
 
                QAtomicInt m_queueSize;
67
 
                QAtomicInt m_itemsDone;
68
 
                OperationMode m_opMode;
69
 
 
70
 
        } ;
71
 
 
72
 
 
73
 
        MixerWorkerThread( Mixer* mixer );
74
 
        virtual ~MixerWorkerThread();
75
 
 
76
 
        virtual void quit();
77
 
 
78
 
        static void resetJobQueue( JobQueue::OperationMode _opMode =
79
 
                                                                                                        JobQueue::Static )
80
 
        {
81
 
                globalJobQueue.reset( _opMode );
82
 
        }
83
 
 
84
 
        static void addJob( ThreadableJob * _job )
85
 
        {
86
 
                globalJobQueue.addJob( _job );
87
 
        }
88
 
 
89
 
        // a convenient helper function allowing to pass a container with pointers
90
 
        // to ThreadableJob objects
91
 
        template<typename T>
92
 
        static void fillJobQueue( const T & _vec,
93
 
                                                        JobQueue::OperationMode _opMode = JobQueue::Static )
94
 
        {
95
 
                resetJobQueue( _opMode );
96
 
                for( typename T::ConstIterator it = _vec.begin(); it != _vec.end(); ++it )
97
 
                {
98
 
                        addJob( *it );
99
 
                }
100
 
        }
101
 
 
102
 
        static void startAndWaitForJobs();
103
 
 
104
 
 
105
 
private:
106
 
        virtual void run();
107
 
 
108
 
        static JobQueue globalJobQueue;
109
 
        static QWaitCondition * queueReadyWaitCond;
110
 
        static QList<MixerWorkerThread *> workerThreads;
111
 
 
112
 
        sampleFrame * m_workingBuf;
113
 
        volatile bool m_quit;
114
 
 
115
 
} ;
116
 
 
117
 
 
118
 
#endif