kwave  18.07.70
Kwave::FixedPool< SIZE, T > Class Template Reference

#include <FixedPool.h>

Collaboration diagram for Kwave::FixedPool< SIZE, T >:
Collaboration graph

Public Member Functions

 FixedPool ()
 
virtual ~FixedPool ()
 
T * allocate ()
 
void release (T *element)
 

Private Attributes

m_storage [SIZE]
 
QQueue< T * > m_free_queue
 
QSemaphore m_sem_free
 
QMutex m_lock
 

Detailed Description

template<unsigned int SIZE, class T>
class Kwave::FixedPool< SIZE, T >

Definition at line 30 of file FixedPool.h.

Constructor & Destructor Documentation

◆ FixedPool()

template<unsigned int SIZE, class T>
Kwave::FixedPool< SIZE, T >::FixedPool ( )
inline

Constructor

Definition at line 34 of file FixedPool.h.

36  {
37  for (unsigned int i = 0; i < SIZE; ++i)
38  release(&(m_storage[i]));
39  }
void release(T *element)
Definition: FixedPool.h:60
T m_storage[SIZE]
Definition: FixedPool.h:68
QQueue< T * > m_free_queue
Definition: FixedPool.h:71
QSemaphore m_sem_free
Definition: FixedPool.h:74

◆ ~FixedPool()

template<unsigned int SIZE, class T>
virtual Kwave::FixedPool< SIZE, T >::~FixedPool ( )
inlinevirtual

Destructor

Definition at line 42 of file FixedPool.h.

42 { }

Member Function Documentation

◆ allocate()

template<unsigned int SIZE, class T>
T* Kwave::FixedPool< SIZE, T >::allocate ( )
inline

Allocate an element from the pool

Returns
pointer to an element

Definition at line 48 of file FixedPool.h.

48  {
49  m_sem_free.acquire();
50  {
51  QMutexLocker _lock(&m_lock);
52  return m_free_queue.dequeue();
53  }
54  }
QQueue< T * > m_free_queue
Definition: FixedPool.h:71
QSemaphore m_sem_free
Definition: FixedPool.h:74

◆ release()

template<unsigned int SIZE, class T>
void Kwave::FixedPool< SIZE, T >::release ( T *  element)
inline

Release an element and put it back into the pool

Parameters
elementpointer to an element

Definition at line 60 of file FixedPool.h.

Referenced by Kwave::FixedPool< MAX_FFT_JOBS, Kwave::SonagramPlugin::Slice >::FixedPool().

60  {
61  QMutexLocker _lock(&m_lock);
62  m_free_queue.enqueue(element);
63  m_sem_free.release();
64  }
QQueue< T * > m_free_queue
Definition: FixedPool.h:71
QSemaphore m_sem_free
Definition: FixedPool.h:74
Here is the caller graph for this function:

Member Data Documentation

◆ m_free_queue

template<unsigned int SIZE, class T>
QQueue<T *> Kwave::FixedPool< SIZE, T >::m_free_queue
private

◆ m_lock

template<unsigned int SIZE, class T>
QMutex Kwave::FixedPool< SIZE, T >::m_lock
private

◆ m_sem_free

template<unsigned int SIZE, class T>
QSemaphore Kwave::FixedPool< SIZE, T >::m_sem_free
private

◆ m_storage

template<unsigned int SIZE, class T>
T Kwave::FixedPool< SIZE, T >::m_storage[SIZE]
private

array used as storage for the pool elements

Definition at line 68 of file FixedPool.h.

Referenced by Kwave::FixedPool< MAX_FFT_JOBS, Kwave::SonagramPlugin::Slice >::FixedPool().


The documentation for this class was generated from the following file: