GNU Radio C++ API Reference
3.10.11.0
The Free & Open Software Radio Ecosystem
Loading...
Searching...
No Matches
pmt_pool.h
Go to the documentation of this file.
1
/* -*- c++ -*- */
2
/*
3
* Copyright 2007,2009,2013 Free Software Foundation, Inc.
4
*
5
* This file is part of GNU Radio
6
*
7
* SPDX-License-Identifier: GPL-3.0-or-later
8
*
9
*/
10
#ifndef INCLUDED_PMT_POOL_H
11
#define INCLUDED_PMT_POOL_H
12
13
#include <condition_variable>
14
#include <
pmt/api.h
>
15
#include <cstddef>
16
#include <mutex>
17
#include <vector>
18
19
namespace
pmt
{
20
21
/*!
22
* \brief very simple thread-safe fixed-size allocation pool
23
*
24
* FIXME may want to go to global allocation with per-thread free list.
25
* This would eliminate virtually all lock contention.
26
*/
27
class
PMT_API
pmt_pool
28
{
29
30
struct
PMT_API
item {
31
struct
item* d_next;
32
};
33
34
using
scoped_lock = std::unique_lock<std::mutex>;
35
mutable
std::mutex d_mutex;
36
std::condition_variable d_cond;
37
38
size_t
d_itemsize;
39
size_t
d_alignment;
40
size_t
d_allocation_size;
41
size_t
d_max_items;
42
size_t
d_n_items;
43
item* d_freelist;
44
std::vector<char*> d_allocations;
45
46
public
:
47
/*!
48
* \param itemsize size in bytes of the items to be allocated.
49
* \param alignment alignment in bytes of all objects to be allocated (must be
50
*power-of-2). \param allocation_size number of bytes to allocate at a time from the
51
*underlying allocator. \param max_items is the maximum number of items to allocate.
52
*If this number is exceeded, the allocate blocks. 0 implies no limit.
53
*/
54
pmt_pool
(
size_t
itemsize,
55
size_t
alignment = 16,
56
size_t
allocation_size = 4096,
57
size_t
max_items = 0);
58
~pmt_pool
();
59
60
void
*
malloc
();
61
void
free
(
void
* p);
62
};
63
64
}
/* namespace pmt */
65
66
#endif
/* INCLUDED_PMT_POOL_H */
pmt::pmt_pool::free
void free(void *p)
pmt::pmt_pool::malloc
void * malloc()
pmt::pmt_pool::pmt_pool
pmt_pool(size_t itemsize, size_t alignment=16, size_t allocation_size=4096, size_t max_items=0)
pmt::pmt_pool::~pmt_pool
~pmt_pool()
api.h
PMT_API
#define PMT_API
Definition
gnuradio-runtime/include/pmt/api.h:18
pmt
Definition
pmt.h:38
gnuradio-runtime
include
pmt
pmt_pool.h
Generated by
1.13.2