NeoMutt  2025-12-11-276-g10b23b
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
pool.c File Reference

A global pool of Buffers. More...

#include "config.h"
#include <stdio.h>
#include "pool.h"
#include "buffer.h"
#include "logging2.h"
#include "memory.h"
#include "signal2.h"
+ Include dependency graph for pool.c:

Go to the source code of this file.

Functions

static void pool_increase_size (void)
 Increase the size of the Buffer pool.
 
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.
 

Variables

static size_t BufferPoolCount = 0
 Number of buffers in the pool.
 
static size_t BufferPoolLen = 0
 Total size of the pool.
 
static const size_t BufferPoolIncrement = 20
 Amount to increase the size of the pool.
 
static const size_t BufferPoolInitialBufferSize = 1024
 Minimum size for a buffer.
 
static struct Buffer ** BufferPool = NULL
 A pool of buffers.
 
static size_t BufferPoolGetCount = 0
 Statistics: total number of buf_pool_get() calls.
 
static size_t BufferPoolGivenOut = 0
 Statistics: number of buffers currently given out.
 
static size_t BufferPoolMaxGivenOut = 0
 Statistics: maximum number of buffers given out concurrently.
 

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.c.

Function Documentation

◆ pool_increase_size()

static void pool_increase_size ( void )
static

Increase the size of the Buffer pool.

Definition at line 58 of file pool.c.

59{
62
65 {
66 struct Buffer *newbuf = buf_new(NULL);
68 BufferPool[BufferPoolCount++] = newbuf;
69 }
70}
struct Buffer * buf_new(const char *str)
Allocate a new Buffer.
Definition buffer.c:304
void buf_alloc(struct Buffer *buf, size_t new_size)
Make sure a buffer can store at least new_size bytes.
Definition buffer.c:337
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
@ LL_DEBUG1
Log at debug level 1.
Definition logging2.h:45
#define MUTT_MEM_REALLOC(pptr, n, type)
Definition memory.h:55
static const size_t BufferPoolInitialBufferSize
Minimum size for a buffer.
Definition pool.c:44
static const size_t BufferPoolIncrement
Amount to increase the size of the pool.
Definition pool.c:42
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
String manipulation buffer.
Definition buffer.h:36
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buf_pool_cleanup()

void buf_pool_cleanup ( void )

Release the Buffer pool.

Definition at line 75 of file pool.c.

76{
77 mutt_debug(LL_DEBUG3, "%zu of %zu returned to pool\n", BufferPoolCount, BufferPoolLen);
78 mutt_debug(LL_DEBUG3, "pool stats: %zu gets, %zu max buffers in use\n",
80
81 while (BufferPoolCount)
84 BufferPoolLen = 0;
85}
void buf_free(struct Buffer **ptr)
Deallocates a buffer.
Definition buffer.c:319
@ LL_DEBUG3
Log at debug level 3.
Definition logging2.h:47
#define FREE(x)
Free memory and set the pointer to NULL.
Definition memory.h:68
static size_t BufferPoolMaxGivenOut
Statistics: maximum number of buffers given out concurrently.
Definition pool.c:53
static size_t BufferPoolGetCount
Statistics: total number of buf_pool_get() calls.
Definition pool.c:49
+ 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 91 of file pool.c.

92{
93 if (BufferPoolCount == 0)
96
101
102 return BufferPool[--BufferPoolCount];
103}
static void pool_increase_size(void)
Increase the size of the Buffer pool.
Definition pool.c:58
static size_t BufferPoolGivenOut
Statistics: number of buffers currently given out.
Definition pool.c:51
#define ASSERT(COND)
Definition signal2.h:59
+ 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 111 of file pool.c.

112{
113 if (!ptr || !*ptr)
114 return;
115
116 if (BufferPoolGivenOut > 0)
118
120 {
121 // LCOV_EXCL_START
122 mutt_debug(LL_DEBUG1, "Internal buffer pool error\n");
123 buf_free(ptr);
124 return;
125 // LCOV_EXCL_STOP
126 }
127
128 // Reset the size if it's too big or too small
129 struct Buffer *buf = *ptr;
130 if ((buf->dsize > (2 * BufferPoolInitialBufferSize)) ||
132 {
134 MUTT_MEM_REALLOC(&buf->data, buf->dsize, char);
135 }
136 buf_reset(buf);
138
139 *ptr = NULL;
140}
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition buffer.c:76
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:

Variable Documentation

◆ BufferPoolCount

size_t BufferPoolCount = 0
static

Number of buffers in the pool.

Definition at line 38 of file pool.c.

◆ BufferPoolLen

size_t BufferPoolLen = 0
static

Total size of the pool.

Definition at line 40 of file pool.c.

◆ BufferPoolIncrement

const size_t BufferPoolIncrement = 20
static

Amount to increase the size of the pool.

Definition at line 42 of file pool.c.

◆ BufferPoolInitialBufferSize

const size_t BufferPoolInitialBufferSize = 1024
static

Minimum size for a buffer.

Definition at line 44 of file pool.c.

◆ BufferPool

struct Buffer** BufferPool = NULL
static

A pool of buffers.

Definition at line 46 of file pool.c.

◆ BufferPoolGetCount

size_t BufferPoolGetCount = 0
static

Statistics: total number of buf_pool_get() calls.

Definition at line 49 of file pool.c.

◆ BufferPoolGivenOut

size_t BufferPoolGivenOut = 0
static

Statistics: number of buffers currently given out.

Definition at line 51 of file pool.c.

◆ BufferPoolMaxGivenOut

size_t BufferPoolMaxGivenOut = 0
static

Statistics: maximum number of buffers given out concurrently.

Definition at line 53 of file pool.c.