xoreos  0.0.5
queueman.cpp
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #include "src/graphics/queueman.h"
26 #include "src/graphics/queueable.h"
27 
29 
30 namespace Graphics {
31 
32 static bool queueComp(Queueable *a, Queueable *b) {
33  return *a < *b;
34 }
35 
36 
38 }
39 
42 }
43 
45  _queueMutex[queue].lock();
46 }
47 
49  _queueMutex[queue].unlock();
50 }
51 
53  Common::StackLock lock(_queueMutex[queue]);
54 
55  return _queue[queue].empty();
56 }
57 
58 const std::list<Queueable *> &QueueManager::getQueue(QueueType queue) const {
59  return _queue[queue];
60 }
61 
63  lockQueue(queue);
64 
65  _queue[queue].sort(queueComp);
66 
67  unlockQueue(queue);
68 }
69 
70 std::list<Queueable *>::iterator QueueManager::addToQueue(QueueType queue, Queueable &q) {
71  lockQueue(queue);
72 
73  _queue[queue].push_back(&q);
74  std::list<Queueable *>::iterator ref = --_queue[queue].end();
75 
76  unlockQueue(queue);
77 
78  return ref;
79 }
80 
82  const std::list<Queueable *>::iterator &ref) {
83 
84  lockQueue(queue);
85 
86  _queue[queue].erase(ref);
87 
88  unlockQueue(queue);
89 }
90 
92  lockQueue(queue);
93 
94  for (std::list<Queueable *>::iterator q = _queue[queue].begin();
95  q != _queue[queue].end(); ++q)
96  (*q)->kickedOut(queue);
97 
98  _queue[queue].clear();
99 
100  unlockQueue(queue);
101 }
102 
104  for (int i = 0; i < kQueueMAX; i++)
105  clearQueue((QueueType) i);
106 }
107 
108 } // End of namespace Graphics
The graphics queue manager.
Definition: queueman.h:41
std::list< Queueable * >::iterator addToQueue(QueueType queue, Queueable &q)
Definition: queueman.cpp:70
For range checks.
Definition: types.h:86
std::list< Queueable * > _queue[kQueueMAX]
Definition: queueman.h:60
void lockQueue(QueueType queue)
Definition: queueman.cpp:44
void sortQueue(QueueType queue)
Definition: queueman.cpp:62
Common::Mutex _queueMutex[kQueueMAX]
Definition: queueman.h:59
QueueType
Definition: types.h:71
#define DECLARE_SINGLETON(T)
Note that you need to use this macro from the global namespace.
Definition: singleton.h:122
const std::list< Queueable * > & getQueue(QueueType queue) const
Definition: queueman.cpp:58
static bool queueComp(Queueable *a, Queueable *b)
Definition: queueman.cpp:32
The graphics queue manager.
Convenience class that locks a mutex on creation and unlocks it on destruction.
Definition: mutex.h:71
void unlockQueue(QueueType queue)
Definition: queueman.cpp:48
void removeFromQueue(QueueType queue, const std::list< Queueable *>::iterator &ref)
Definition: queueman.cpp:81
An object that can be stored in a queue.
void lock()
Definition: mutex.cpp:41
void clearQueue(QueueType queue)
Definition: queueman.cpp:91
void unlock()
Definition: mutex.cpp:47
bool isQueueEmpty(QueueType queue)
Definition: queueman.cpp:52