GNU Radio Manual and C++ API Reference
3.9.4.0
The Free & Open Software Radio Ecosystem
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 <
pmt/api.h
>
14
#include <boost/thread.hpp>
15
#include <cstddef>
16
#include <vector>
17
18
namespace
pmt
{
19
20
/*!
21
* \brief very simple thread-safe fixed-size allocation pool
22
*
23
* FIXME may want to go to global allocation with per-thread free list.
24
* This would eliminate virtually all lock contention.
25
*/
26
class
PMT_API
pmt_pool
27
{
28
29
struct
PMT_API
item {
30
struct
item* d_next;
31
};
32
33
typedef
boost::unique_lock<boost::mutex>
scoped_lock
;
34
mutable
boost::mutex
d_mutex;
35
boost::condition_variable
d_cond;
36
37
size_t
d_itemsize;
38
size_t
d_alignment;
39
size_t
d_allocation_size;
40
size_t
d_max_items;
41
size_t
d_n_items;
42
item* d_freelist;
43
std::vector<char*> d_allocations;
44
45
public
:
46
/*!
47
* \param itemsize size in bytes of the items to be allocated.
48
* \param alignment alignment in bytes of all objects to be allocated (must be
49
*power-of-2). \param allocation_size number of bytes to allocate at a time from the
50
*underlying allocator. \param max_items is the maximum number of items to allocate.
51
*If this number is exceeded, the allocate blocks. 0 implies no limit.
52
*/
53
pmt_pool
(
size_t
itemsize
,
54
size_t
alignment = 16,
55
size_t
allocation_size = 4096,
56
size_t
max_items = 0);
57
~
pmt_pool
();
58
59
void
* malloc();
60
void
free(
void
* p);
61
};
62
63
}
/* namespace pmt */
64
65
#endif
/* INCLUDED_PMT_POOL_H */
gr::blocks::pdu::itemsize
BLOCKS_API size_t itemsize(vector_type type)
gr::thread::condition_variable
boost::condition_variable condition_variable
Definition:
thread.h:39
PMT_API
#define PMT_API
Definition:
gnuradio-runtime/include/pmt/api.h:18
api.h
gr::thread::mutex
boost::mutex mutex
Definition:
thread.h:37
pmt::pmt_pool
very simple thread-safe fixed-size allocation pool
Definition:
pmt_pool.h:26
gr::thread::scoped_lock
boost::unique_lock< boost::mutex > scoped_lock
Definition:
thread.h:38
pmt
Definition:
pmt.h:39
gnuradio-runtime
include
pmt
pmt_pool.h
Generated by
1.8.17