NeoMutt  2025-01-09-81-g753ae0
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
pool.h File Reference

A global pool of Buffers. More...

+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void buf_pool_cleanup (void)
 Release the Buffer pool.
 
struct Bufferbuf_pool_get (void)
 Get a Buffer from the pool.
 
void buf_pool_release (struct Buffer **ptr)
 Return a Buffer to the pool.
 

Detailed Description

A global pool of Buffers.

Authors
  • Richard Russon

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file pool.h.

Function Documentation

◆ buf_pool_cleanup()

void buf_pool_cleanup ( void  )

Release the Buffer pool.

Definition at line 68 of file pool.c.

69{
70 mutt_debug(LL_DEBUG1, "%zu of %zu returned to pool\n", BufferPoolCount, BufferPoolLen);
71
72 while (BufferPoolCount)
75 BufferPoolLen = 0;
76}
void buf_free(struct Buffer **ptr)
Deallocates a buffer.
Definition: buffer.c:319
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
@ LL_DEBUG1
Log at debug level 1.
Definition: logging2.h:43
#define FREE(x)
Definition: memory.h:55
static size_t BufferPoolLen
Total size of the pool.
Definition: pool.c:40
static size_t BufferPoolCount
Number of buffers in the pool.
Definition: pool.c:38
static struct Buffer ** BufferPool
A pool of buffers.
Definition: pool.c:46
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buf_pool_get()

struct Buffer * buf_pool_get ( void  )

Get a Buffer from the pool.

Return values
ptrBuffer

Definition at line 82 of file pool.c.

83{
84 if (BufferPoolCount == 0)
88}
static void pool_increase_size(void)
Increase the size of the Buffer pool.
Definition: pool.c:51
#define ASSERT(COND)
Definition: signal2.h:60
+ Here is the call graph for this function:

◆ buf_pool_release()

void buf_pool_release ( struct Buffer **  ptr)

Return a Buffer to the pool.

Parameters
[out]ptrBuffer to release
Note
The pointer will be NULL'd

Definition at line 96 of file pool.c.

97{
98 if (!ptr || !*ptr)
99 return;
100
102 {
103 // LCOV_EXCL_START
104 mutt_debug(LL_DEBUG1, "Internal buffer pool error\n");
105 buf_free(ptr);
106 return;
107 // LCOV_EXCL_STOP
108 }
109
110 // Reset the size if it's too big or too small
111 struct Buffer *buf = *ptr;
112 if ((buf->dsize > (2 * BufferPoolInitialBufferSize)) ||
114 {
116 MUTT_MEM_REALLOC(&buf->data, buf->dsize, char);
117 }
118 buf_reset(buf);
120
121 *ptr = NULL;
122}
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:76
#define MUTT_MEM_REALLOC(pptr, n, type)
Definition: memory.h:43
static const size_t BufferPoolInitialBufferSize
Minimum size for a buffer.
Definition: pool.c:44
String manipulation buffer.
Definition: buffer.h:36
size_t dsize
Length of data.
Definition: buffer.h:39
char * data
Pointer to data.
Definition: buffer.h:37
+ Here is the call graph for this function: