kwave
18.07.70
Main Page
Related Pages
+
Namespaces
Namespace List
+
Namespace Members
+
All
_
a
b
c
f
h
i
l
m
o
p
r
s
t
u
w
y
z
Functions
Typedefs
Enumerations
+
Enumerator
a
b
c
f
i
l
o
p
r
s
u
w
+
Classes
Class List
Class Index
Class Hierarchy
+
Class Members
+
All
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
+
Functions
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
z
~
+
Variables
a
b
c
d
e
f
g
h
i
m
n
p
r
s
t
v
w
x
y
z
Typedefs
Enumerations
+
Enumerator
a
b
c
d
e
f
g
i
l
m
n
o
p
r
s
t
u
v
w
Related Functions
+
Files
File List
+
File Members
+
All
_
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
+
Functions
_
a
b
c
d
e
f
i
l
m
p
q
r
s
t
x
z
Variables
Typedefs
+
Macros
_
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
r
s
t
u
v
w
x
z
FixedPool.h
Go to the documentation of this file.
1
/***************************************************************************
2
FixedPool.h - simple pool with fixed number of elements
3
-------------------
4
begin : Thu Jan 02 2014
5
copyright : (C) 2014 by Thomas Eschenbacher
6
email : Thomas.Eschenbacher@gmx.de
7
***************************************************************************/
8
9
/***************************************************************************
10
* *
11
* This program is free software; you can redistribute it and/or modify *
12
* it under the terms of the GNU General Public License as published by *
13
* the Free Software Foundation; either version 2 of the License, or *
14
* (at your option) any later version. *
15
* *
16
***************************************************************************/
17
18
#ifndef FIXED_POOL_H
19
#define FIXED_POOL_H
20
21
#include "config.h"
22
23
#include <QMutex>
24
#include <QMutexLocker>
25
#include <QQueue>
26
#include <QSemaphore>
27
28
namespace
Kwave
29
{
30
template
<
unsigned
int
SIZE,
class
T>
class
FixedPool
31
{
32
public
:
34
FixedPool
()
35
:
m_storage
(),
m_free_queue
(),
m_sem_free
(0),
m_lock
()
36
{
37
for
(
unsigned
int
i = 0; i < SIZE; ++i)
38
release
(&(
m_storage
[i]));
39
}
40
42
virtual
~FixedPool
() { }
43
48
T *
allocate
() {
49
m_sem_free
.acquire();
50
{
51
QMutexLocker _lock(&
m_lock
);
52
return
m_free_queue
.dequeue();
53
}
54
}
55
60
void
release
(T *element) {
61
QMutexLocker _lock(&
m_lock
);
62
m_free_queue
.enqueue(element);
63
m_sem_free
.release();
64
}
65
66
private
:
68
T
m_storage
[SIZE];
69
71
QQueue<T *>
m_free_queue
;
72
74
QSemaphore
m_sem_free
;
75
77
QMutex
m_lock
;
78
};
79
}
80
81
#endif
/* FIXED_POOL_H */
82
83
//***************************************************************************
84
//***************************************************************************
Kwave
Definition:
App.h:33
Kwave::FixedPool::FixedPool
FixedPool()
Definition:
FixedPool.h:34
Kwave::FixedPool::release
void release(T *element)
Definition:
FixedPool.h:60
Kwave::FixedPool::m_storage
T m_storage[SIZE]
Definition:
FixedPool.h:68
Kwave::FixedPool::m_free_queue
QQueue< T * > m_free_queue
Definition:
FixedPool.h:71
Kwave::FixedPool::m_lock
QMutex m_lock
Definition:
FixedPool.h:77
Kwave::FixedPool::allocate
T * allocate()
Definition:
FixedPool.h:48
Kwave::FixedPool::~FixedPool
virtual ~FixedPool()
Definition:
FixedPool.h:42
Kwave::FixedPool::m_sem_free
QSemaphore m_sem_free
Definition:
FixedPool.h:74
Kwave::FixedPool
Definition:
FixedPool.h:30
libkwave
FixedPool.h
Generated on Sat Mar 24 2018 09:10:25 for kwave by
1.8.13