ardour
Public Member Functions | Private Attributes | List of all members
CrossThreadPool Class Reference

#include <pool.h>

Inheritance diagram for CrossThreadPool:
Pool

Public Member Functions

 CrossThreadPool (std::string n, unsigned long isize, unsigned long nitems, PerThreadPool *)
 
void * alloc ()
 
void push (void *)
 
PerThreadPoolparent () const
 
bool empty ()
 
guint pending_size () const
 
void flush_pending ()
 
void flush_pending_with_ev (void *)
 
- Public Member Functions inherited from Pool
 Pool (std::string name, unsigned long item_size, unsigned long nitems)
 
virtual ~Pool ()
 
virtual void release (void *)
 
std::string name () const
 
guint available () const
 
guint used () const
 
guint total () const
 

Private Attributes

RingBuffer< void * > pending
 
PerThreadPool_parent
 

Additional Inherited Members

- Protected Attributes inherited from Pool
RingBuffer< void * > free_list
 a list of pointers to free items within block More...
 
std::string _name
 

Detailed Description

Management of a per-thread pool of data that is allocated by one thread and freed by one other thread. Not safe for use when there is more than 1 reader and 1 writer.

This is basically a wrapper around a thread-local storage instance of a ringbuffer, made safe for use in the case where multiple threads allocate from the ringbuffer and a single thread "frees" the allocations.

Rather than using locks, each thread has its own ringbuffer (and associated data), and so it calls alloc(), passes a pointer to the result of the alloc to another thread, which later calls push() to "free" it.

Definition at line 97 of file pool.h.

Constructor & Destructor Documentation

CrossThreadPool::CrossThreadPool ( std::string  n,
unsigned long  isize,
unsigned long  nitems,
PerThreadPool  
)

Definition at line 217 of file pool.cc.

Member Function Documentation

void * CrossThreadPool::alloc ( )
virtual

Allocate an item's worth of memory in the Pool by taking one from the free list.

Returns
Pointer to free item.

Reimplemented from Pool.

Definition at line 253 of file pool.cc.

bool CrossThreadPool::empty ( )
Returns
true if there is nothing in this pool

Definition at line 269 of file pool.cc.

void CrossThreadPool::flush_pending ( )

Definition at line 233 of file pool.cc.

void CrossThreadPool::flush_pending_with_ev ( void *  ptr)

Definition at line 226 of file pool.cc.

PerThreadPool* CrossThreadPool::parent ( ) const
inline

Definition at line 105 of file pool.h.

guint CrossThreadPool::pending_size ( ) const
inline

Definition at line 110 of file pool.h.

void CrossThreadPool::push ( void *  t)

Definition at line 262 of file pool.cc.

Member Data Documentation

PerThreadPool* CrossThreadPool::_parent
private

Definition at line 117 of file pool.h.

RingBuffer<void*> CrossThreadPool::pending
private

Definition at line 116 of file pool.h.


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