2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-29 13:38:26 +00:00

Use restrict and const in isc_mempool_t

This commit makes add restrict and const modifiers to some variables
to aid compiler to do its optimizations.
This commit is contained in:
Artem Boldariev 2021-07-09 14:24:33 +03:00 committed by Ondřej Surý
parent c11a401add
commit 3673abc53c
2 changed files with 32 additions and 28 deletions

View File

@ -364,7 +364,7 @@ isc_mem_renderjson(void *memobj0);
#define isc_mempool_create(c, s, mp) \ #define isc_mempool_create(c, s, mp) \
isc__mempool_create((c), (s), (mp)_ISC_MEM_FILELINE) isc__mempool_create((c), (s), (mp)_ISC_MEM_FILELINE)
void void
isc__mempool_create(isc_mem_t *mctx, size_t size, isc__mempool_create(isc_mem_t *restrict mctx, const size_t element_size,
isc_mempool_t **mpctxp _ISC_MEM_FLARG); isc_mempool_t **mpctxp _ISC_MEM_FLARG);
/*%< /*%<
* Create a memory pool. * Create a memory pool.
@ -385,7 +385,7 @@ isc__mempool_create(isc_mem_t *mctx, size_t size,
#define isc_mempool_destroy(mp) isc__mempool_destroy((mp)_ISC_MEM_FILELINE) #define isc_mempool_destroy(mp) isc__mempool_destroy((mp)_ISC_MEM_FILELINE)
void void
isc__mempool_destroy(isc_mempool_t **mpctxp _ISC_MEM_FLARG); isc__mempool_destroy(isc_mempool_t **restrict mpctxp _ISC_MEM_FLARG);
/*%< /*%<
* Destroy a memory pool. * Destroy a memory pool.
* *
@ -395,7 +395,7 @@ isc__mempool_destroy(isc_mempool_t **mpctxp _ISC_MEM_FLARG);
*/ */
void void
isc_mempool_setname(isc_mempool_t *mpctx, const char *name); isc_mempool_setname(isc_mempool_t *restrict mpctx, const char *name);
/*%< /*%<
* Associate a name with a memory pool. At most 15 characters may be * Associate a name with a memory pool. At most 15 characters may be
*used. *used.
@ -418,38 +418,39 @@ isc_mempool_setname(isc_mempool_t *mpctx, const char *name);
*/ */
unsigned int unsigned int
isc_mempool_getfreemax(isc_mempool_t *mpctx); isc_mempool_getfreemax(isc_mempool_t *restrict mpctx);
/*%< /*%<
* Returns the maximum allowed size of the free list. * Returns the maximum allowed size of the free list.
*/ */
void void
isc_mempool_setfreemax(isc_mempool_t *mpctx, unsigned int limit); isc_mempool_setfreemax(isc_mempool_t *restrict mpctx, const unsigned int limit);
/*%< /*%<
* Sets the maximum allowed size of the free list. * Sets the maximum allowed size of the free list.
*/ */
unsigned int unsigned int
isc_mempool_getfreecount(isc_mempool_t *mpctx); isc_mempool_getfreecount(isc_mempool_t *restrict mpctx);
/*%< /*%<
* Returns current size of the free list. * Returns current size of the free list.
*/ */
unsigned int unsigned int
isc_mempool_getallocated(isc_mempool_t *mpctx); isc_mempool_getallocated(isc_mempool_t *restrict mpctx);
/*%< /*%<
* Returns the number of items allocated from this pool. * Returns the number of items allocated from this pool.
*/ */
unsigned int unsigned int
isc_mempool_getfillcount(isc_mempool_t *mpctx); isc_mempool_getfillcount(isc_mempool_t *restrict mpctx);
/*%< /*%<
* Returns the number of items allocated as a block from the parent * Returns the number of items allocated as a block from the parent
* memory context when the free list is empty. * memory context when the free list is empty.
*/ */
void void
isc_mempool_setfillcount(isc_mempool_t *mpctx, unsigned int limit); isc_mempool_setfillcount(isc_mempool_t *restrict mpctx,
const unsigned int limit);
/*%< /*%<
* Sets the fillcount. * Sets the fillcount.
* *

View File

@ -1106,9 +1106,10 @@ isc_mem_getname(isc_mem_t *ctx) {
*/ */
void void
isc__mempool_create(isc_mem_t *mctx, size_t size, isc__mempool_create(isc_mem_t *restrict mctx, const size_t element_size,
isc_mempool_t **mpctxp FLARG) { isc_mempool_t **restrict mpctxp FLARG) {
isc_mempool_t *mpctx = NULL; isc_mempool_t *restrict mpctx = NULL;
size_t size = element_size;
REQUIRE(VALID_CONTEXT(mctx)); REQUIRE(VALID_CONTEXT(mctx));
REQUIRE(size > 0U); REQUIRE(size > 0U);
@ -1151,7 +1152,7 @@ isc__mempool_create(isc_mem_t *mctx, size_t size,
} }
void void
isc_mempool_setname(isc_mempool_t *mpctx, const char *name) { isc_mempool_setname(isc_mempool_t *restrict mpctx, const char *name) {
REQUIRE(VALID_MEMPOOL(mpctx)); REQUIRE(VALID_MEMPOOL(mpctx));
REQUIRE(name != NULL); REQUIRE(name != NULL);
@ -1159,10 +1160,10 @@ isc_mempool_setname(isc_mempool_t *mpctx, const char *name) {
} }
void void
isc__mempool_destroy(isc_mempool_t **mpctxp FLARG) { isc__mempool_destroy(isc_mempool_t **restrict mpctxp FLARG) {
isc_mempool_t *mpctx = NULL; isc_mempool_t *restrict mpctx = NULL;
isc_mem_t *mctx = NULL; isc_mem_t *mctx = NULL;
element *item = NULL; element *restrict item = NULL;
REQUIRE(mpctxp != NULL); REQUIRE(mpctxp != NULL);
REQUIRE(VALID_MEMPOOL(*mpctxp)); REQUIRE(VALID_MEMPOOL(*mpctxp));
@ -1216,7 +1217,7 @@ isc__mempool_destroy(isc_mempool_t **mpctxp FLARG) {
#if __SANITIZE_ADDRESS__ #if __SANITIZE_ADDRESS__
void * void *
isc__mempool_get(isc_mempool_t *mpctx FLARG) { isc__mempool_get(isc_mempool_t *restrict mpctx FLARG) {
REQUIRE(VALID_MEMPOOL(mpctx)); REQUIRE(VALID_MEMPOOL(mpctx));
mpctx->allocated++; mpctx->allocated++;
@ -1226,7 +1227,7 @@ isc__mempool_get(isc_mempool_t *mpctx FLARG) {
} }
void void
isc__mempool_put(isc_mempool_t *mpctx, void *mem FLARG) { isc__mempool_put(isc_mempool_t *restrict mpctx, void *mem FLARG) {
REQUIRE(VALID_MEMPOOL(mpctx)); REQUIRE(VALID_MEMPOOL(mpctx));
REQUIRE(mem != NULL); REQUIRE(mem != NULL);
@ -1236,8 +1237,8 @@ isc__mempool_put(isc_mempool_t *mpctx, void *mem FLARG) {
#else /* __SANITIZE_ADDRESS__ */ #else /* __SANITIZE_ADDRESS__ */
void * void *
isc__mempool_get(isc_mempool_t *mpctx FLARG) { isc__mempool_get(isc_mempool_t *restrict mpctx FLARG) {
element *item = NULL; element *restrict item = NULL;
REQUIRE(VALID_MEMPOOL(mpctx)); REQUIRE(VALID_MEMPOOL(mpctx));
@ -1275,8 +1276,8 @@ isc__mempool_get(isc_mempool_t *mpctx FLARG) {
/* coverity[+free : arg-1] */ /* coverity[+free : arg-1] */
void void
isc__mempool_put(isc_mempool_t *mpctx, void *mem FLARG) { isc__mempool_put(isc_mempool_t *restrict mpctx, void *mem FLARG) {
element *item = NULL; element *restrict item = NULL;
REQUIRE(VALID_MEMPOOL(mpctx)); REQUIRE(VALID_MEMPOOL(mpctx));
REQUIRE(mem != NULL); REQUIRE(mem != NULL);
@ -1315,35 +1316,37 @@ isc__mempool_put(isc_mempool_t *mpctx, void *mem FLARG) {
*/ */
void void
isc_mempool_setfreemax(isc_mempool_t *mpctx, unsigned int limit) { isc_mempool_setfreemax(isc_mempool_t *restrict mpctx,
const unsigned int limit) {
REQUIRE(VALID_MEMPOOL(mpctx)); REQUIRE(VALID_MEMPOOL(mpctx));
mpctx->freemax = limit; mpctx->freemax = limit;
} }
unsigned int unsigned int
isc_mempool_getfreemax(isc_mempool_t *mpctx) { isc_mempool_getfreemax(isc_mempool_t *restrict mpctx) {
REQUIRE(VALID_MEMPOOL(mpctx)); REQUIRE(VALID_MEMPOOL(mpctx));
return (mpctx->freemax); return (mpctx->freemax);
} }
unsigned int unsigned int
isc_mempool_getfreecount(isc_mempool_t *mpctx) { isc_mempool_getfreecount(isc_mempool_t *restrict mpctx) {
REQUIRE(VALID_MEMPOOL(mpctx)); REQUIRE(VALID_MEMPOOL(mpctx));
return (mpctx->freecount); return (mpctx->freecount);
} }
unsigned int unsigned int
isc_mempool_getallocated(isc_mempool_t *mpctx) { isc_mempool_getallocated(isc_mempool_t *restrict mpctx) {
REQUIRE(VALID_MEMPOOL(mpctx)); REQUIRE(VALID_MEMPOOL(mpctx));
return (mpctx->allocated); return (mpctx->allocated);
} }
void void
isc_mempool_setfillcount(isc_mempool_t *mpctx, unsigned int limit) { isc_mempool_setfillcount(isc_mempool_t *restrict mpctx,
unsigned int const limit) {
REQUIRE(VALID_MEMPOOL(mpctx)); REQUIRE(VALID_MEMPOOL(mpctx));
REQUIRE(limit > 0); REQUIRE(limit > 0);
@ -1351,7 +1354,7 @@ isc_mempool_setfillcount(isc_mempool_t *mpctx, unsigned int limit) {
} }
unsigned int unsigned int
isc_mempool_getfillcount(isc_mempool_t *mpctx) { isc_mempool_getfillcount(isc_mempool_t *restrict mpctx) {
REQUIRE(VALID_MEMPOOL(mpctx)); REQUIRE(VALID_MEMPOOL(mpctx));
return (mpctx->fillcount); return (mpctx->fillcount);