Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
src
ipDeviceCommon
MemoryPool.h
Go to the documentation of this file.
1
// License: Apache 2.0. See LICENSE file in root directory.
2
// Copyright(c) 2020 Intel Corporation. All Rights Reserved.
3
4
#pragma once
5
6
#include <
ipDeviceCommon/RsCommon.h
>
7
8
#include <iostream>
9
#include <mutex>
10
#include <queue>
11
12
#include "
NetdevLog.h
"
13
14
#define POOL_SIZE 100
15
16
class
MemoryPool
17
{
18
19
public
:
20
MemoryPool
()
21
{
22
// //alloc memory
23
// std::unique_lock<std::mutex> lk(m_mutex);
24
// for(int i = 0; i < POOL_SIZE; i++)
25
// {
26
// unsigned char *mem = new unsigned char[sizeof(RsFrameHeader) + MAX_FRAME_SIZE]; //TODO:to use OutPacketBuffer::maxSize;
27
// m_pool.push(mem);
28
// }
29
// lk.unlock();
30
}
31
32
MemoryPool
(
const
MemoryPool
&
obj
)
33
{
34
m_pool
= obj.
m_pool
;
35
}
36
37
MemoryPool
&
operator=
(
const
MemoryPool
&&
obj
)
38
{
39
m_pool
=
obj
.m_pool;
40
return
*
this
;
41
}
42
43
unsigned
char
*
getNextMem
()
44
{
45
// unsigned char* mem = nullptr;
46
// std::unique_lock<std::mutex> lk(m_mutex);
47
// if(!m_pool.empty())
48
// {
49
// mem = m_pool.front();
50
// m_pool.pop();
51
// }
52
// else
53
// {
54
// ERR << "getNextMem: pool is empty";
55
// }
56
// lk.unlock();
57
// return mem;
58
return
new
unsigned
char
[
sizeof
(
RsFrameHeader
) +
MAX_FRAME_SIZE
];
59
}
60
61
void
returnMem
(
unsigned
char
* t_mem)
62
{
63
// if(t_mem != nullptr)
64
// {
65
// std::unique_lock<std::mutex> lk(m_mutex);
66
// m_pool.push(t_mem);
67
// lk.unlock();
68
// }
69
// else
70
// {
71
// ERR << "returnMem: invalid address";
72
// }
73
delete
[] t_mem;
74
}
75
76
~MemoryPool
()
77
{
78
// std::unique_lock<std::mutex> lk(m_mutex);
79
// while(!m_pool.empty())
80
// {
81
// unsigned char* mem = m_pool.front();
82
// m_pool.pop();
83
// if(mem != nullptr)
84
// {
85
// delete mem;
86
// }
87
// else
88
// {
89
// ERR << "~memory_pool: invalid address";
90
// }
91
// }
92
// lk.unlock();
93
}
94
95
private
:
96
std::queue<unsigned char*>
m_pool
;
97
std::mutex
m_mutex
;
98
};
MemoryPool::m_mutex
std::mutex m_mutex
Definition:
MemoryPool.h:97
MAX_FRAME_SIZE
const int MAX_FRAME_SIZE
Definition:
RsCommon.h:51
obj
GLhandleARB obj
Definition:
glext.h:4157
MemoryPool
Definition:
MemoryPool.h:16
MemoryPool::MemoryPool
MemoryPool(const MemoryPool &obj)
Definition:
MemoryPool.h:32
MemoryPool::returnMem
void returnMem(unsigned char *t_mem)
Definition:
MemoryPool.h:61
NetdevLog.h
MemoryPool::m_pool
std::queue< unsigned char * > m_pool
Definition:
MemoryPool.h:96
MemoryPool::~MemoryPool
~MemoryPool()
Definition:
MemoryPool.h:76
RsCommon.h
RsFrameHeader
Definition:
RsCommon.h:30
MemoryPool::operator=
MemoryPool & operator=(const MemoryPool &&obj)
Definition:
MemoryPool.h:37
MemoryPool::MemoryPool
MemoryPool()
Definition:
MemoryPool.h:20
MemoryPool::getNextMem
unsigned char * getNextMem()
Definition:
MemoryPool.h:43
librealsense2
Author(s): Sergey Dorodnicov
, Doron Hirshberg
, Mark Horn
, Reagan Lopez
, Itay Carpis
autogenerated on Mon May 3 2021 02:47:21