GNU Radio Manual and C++ API Reference 3.10.5.1
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 <condition_variable>
14#include <pmt/api.h>
15#include <cstddef>
16#include <mutex>
17#include <vector>
18
19namespace 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 */
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;
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
46public:
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 */
55 size_t alignment = 16,
56 size_t allocation_size = 4096,
57 size_t max_items = 0);
59
60 void* malloc();
61 void free(void* p);
62};
63
64} /* namespace pmt */
65
66#endif /* INCLUDED_PMT_POOL_H */
very simple thread-safe fixed-size allocation pool
Definition: pmt_pool.h:28
void free(void *p)
void * malloc()
pmt_pool(size_t itemsize, size_t alignment=16, size_t allocation_size=4096, size_t max_items=0)
#define PMT_API
Definition: gnuradio-runtime/include/pmt/api.h:18
GR_RUNTIME_API size_t itemsize(types::vector_type type)
boost::mutex mutex
Definition: thread.h:37
boost::condition_variable condition_variable
Definition: thread.h:39
Definition: pmt.h:38