|
cds
2.3.2
|
Bounded free-list based on bounded lock-free queue cds::intrusive::VyukovMPMCCycleQueue.
More...
#include <cds/memory/vyukov_queue_pool.h>
Public Types | |
| typedef cds::intrusive::VyukovMPMCCycleQueue< T, internal_traits > | queue_type |
| Queue type. | |
| typedef T | value_type |
| Value type. | |
| typedef Traits | traits |
| Pool traits. | |
| typedef traits::allocator::template rebind< value_type >::other | allocator_type |
| allocator type | |
| typedef traits::back_off | back_off |
| back-off strategy | |
Public Member Functions | |
| bounded_vyukov_queue_pool (size_t nCapacity=0) | |
| Preallocates the pool of object. More... | |
| ~bounded_vyukov_queue_pool () | |
| Deallocates the pool. | |
| value_type * | allocate (size_t n) |
| Allocates an object from pool. More... | |
| void | deallocate (value_type *p, size_t n) |
Deallocates the object p. More... | |
Bounded free-list based on bounded lock-free queue cds::intrusive::VyukovMPMCCycleQueue.
Template parameters:
T - the type of object maintaining by free-list. T must be default-constructibleTraits - traits for cds::intrusive::VyukovMPMCCycleQueue class plus cds::opt::allocator option, defaul is vyukov_queue_pool_traits Internals
At construction time, the free-list allocates the array of N items and stores them into the queue, where N is the queue capacity. When allocating the free-list tries to pop an object from internal queue i.e. from preallocated pool. If success the popped object is returned. Otherwise a std::bad_alloc exception is raised. So, the pool can contain up to N items. When deallocating, the object is pushed into the queue. In debug mode deallocate() member function asserts that the pointer is from preallocated pool.
Usage
bounded_vyukov_queue_pool should be used together with pool_allocator. You should declare an static object of type bounded_vyukov_queue_pool, provide an accessor functor to this object and use pool_allocator as an allocator:
|
inline |
Preallocates the pool of object.
nCapacity argument is the queue capacity. It should be passed if the queue is based on dynamically-allocated buffer. See cds::intrusive::VyukovMPMCCycleQueue for explanation.
|
inline |
Allocates an object from pool.
The pool supports allocation only single object (n = 1). If n > 1 the behaviour is undefined.
If the queue is not empty, the popped value is returned. Otherwise, a std::bad_alloc exception is raised.
|
inline |
Deallocates the object p.
The pool supports allocation only single object (n = 1). If n > 1 the behaviour is undefined.
p should be from preallocated pool.