MCPcopy Create free account
hub / github.com/bailey27/cppcryptfs / GetIoBuffer

Method GetIoBuffer

libcppcryptfs/file/iobufferpool.cpp:82–125  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

80
81
82IoBuffer * IoBufferPool::GetIoBuffer(size_t buffer_size, size_t ivbuffer_size)
83{
84
85 IoBuffer* pb = nullptr;
86
87 bool will_be_from_pool = false;
88
89 auto total_size = buffer_size + ivbuffer_size;
90
91 if (total_size <= m_max_pool_buffer_size) {
92
93 lock_guard<mutex> lock(m_mutex);
94
95 if (!m_buffers.empty()) {
96 pb = m_buffers.front();
97 if (total_size > pb->m_storage.size()) {
98 auto growth = total_size - pb->m_storage.size();
99 if (m_current_size + growth > m_max_size) {
100 pb = nullptr;
101 } else {
102 m_current_size += growth;
103 }
104 }
105 if (pb) {
106 m_buffers.pop_front();
107 }
108 } else if (m_current_size + total_size <= m_max_size) {
109 will_be_from_pool = true;
110 m_current_size += total_size;
111 }
112 }
113
114 try {
115 if (pb) {
116 pb->reallocate(buffer_size, ivbuffer_size);
117 } else {
118 pb = new IoBuffer(will_be_from_pool, buffer_size, ivbuffer_size);
119 }
120 } catch (const std::bad_alloc&) {
121 pb = nullptr;
122 }
123
124 return pb;
125}
126
127void IoBufferPool::ReleaseIoBuffer(IoBuffer * pBuf)
128{

Callers 2

ReadMethod · 0.80
WriteMethod · 0.80

Calls 3

emptyMethod · 0.80
sizeMethod · 0.80
reallocateMethod · 0.80

Tested by

no test coverage detected