-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMediaQueue.h
59 lines (49 loc) · 1.19 KB
/
MediaQueue.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#ifndef MEDIAQUEUE_H
#define MEDIAQUEUE_H
#include <QQueue>
#include <QMutex>
#define TRY_LOCK_TIMEOUT 1000*10 //milliseconds
template <class T>
class MediaQueue : public QQueue<T>
{
public:
inline MediaQueue(){
}
inline MediaQueue(const MediaQueue<T>& queue){
QList<T>::QList(queue);
}
inline MediaQueue<T> operator=(const MediaQueue<T>& queue){
*this = queue;
return *this;
}
inline void enqueue(const T &t){
// if(mutex.tryLock(TRY_LOCK_TIMEOUT)){
// QList<T>::append(t);
// mutex.unlock();
// }
mutex.lock();
QList<T>::append(t);
mutex.unlock();
}
inline T dequeue(){
T ret;
// if(mutex.tryLock(TRY_LOCK_TIMEOUT)){
// ret = QList<T>::takeFirst();
// mutex.unlock();
// }
mutex.lock();
if(!QList<T>::isEmpty()){
ret = QList<T>::takeFirst();
}
mutex.unlock();
return ret;
}
void clear(){
mutex.lock();
QList<T>::clear();
mutex.unlock();
}
private:
QMutex mutex;
};
#endif // MEDIAQUEUE_H