FACT++
1.0
Main Page
Related Pages
Namespaces
Classes
Files
Examples
std::shared_ptr<char> MemoryStock::pop
(
bool
block
)
inline
private
Definition at line
42
of file
MemoryManager.h
.
43
{
44
if
(block)
45
{
46
// No free slot available, next alloc would exceed max memory:
47
// block until a slot is available
48
std::unique_lock<std::mutex> lock(
fMutexCond
);
49
while
(
fMemoryStock
.empty() &&
fAllocated
+
fChunkSize
>
fMaxMemory
)
50
fCond
.wait(lock);
51
}
52
else
53
{
54
// No free slot available, next alloc would exceed max memory
55
// return an empty pointer
56
if
(
fMemoryStock
.empty() &&
fAllocated
+
fChunkSize
>
fMaxMemory
)
57
return
std::shared_ptr<char>();
58
}
59
60
// We will return this amount of memory
61
// This is not 100% thread safe, but it is not a super accurate measure anyway
62
fInUse
+=
fChunkSize
;
63
if
(
fInUse
>
fMaxInUse
)
64
fMaxInUse
=
fInUse
;
65
66
if
(
fMemoryStock
.empty())
67
{
68
// No free slot available, allocate a new one
69
fAllocated
+=
fChunkSize
;
70
return
std::shared_ptr<char>(
new
char
[
fChunkSize
]);
71
}
72
73
// Get the next free slot from the stack and return it
74
const
std::lock_guard<std::mutex> lock(
fMutexMem
);
75
76
const
auto
mem =
fMemoryStock
.front();
77
fMemoryStock
.pop_front();
78
return
mem;
79
};
MemoryStock::fMutexMem
std::mutex fMutexMem
Definition:
MemoryManager.h:29
MemoryStock::fMaxInUse
size_t fMaxInUse
Definition:
MemoryManager.h:27
MemoryStock::fCond
std::condition_variable fCond
Definition:
MemoryManager.h:31
MemoryStock::fMaxMemory
size_t fMaxMemory
Definition:
MemoryManager.h:22
MemoryStock::fInUse
size_t fInUse
Definition:
MemoryManager.h:24
MemoryStock::fMemoryStock
std::forward_list< std::shared_ptr< char > > fMemoryStock
Definition:
MemoryManager.h:33
MemoryStock::fAllocated
size_t fAllocated
Definition:
MemoryManager.h:25
MemoryStock::fChunkSize
size_t fChunkSize
Definition:
MemoryManager.h:21
MemoryStock::fMutexCond
std::mutex fMutexCond
Definition:
MemoryManager.h:30
MemoryStock
Generated on Sun Sep 18 2016 20:50:54 for FACT++ by
1.8.11