Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ISC Open Source Projects
BIND
Commits
78b2f25c
Commit
78b2f25c
authored
Oct 19, 1999
by
Michael Graff
Browse files
add isc_mem_setname()
parent
25811a89
Changes
2
Hide whitespace changes
Inline
Side-by-side
lib/isc/include/isc/mem.h
View file @
78b2f25c
...
...
@@ -32,6 +32,12 @@ ISC_LANG_BEGINDECLS
typedef
void
*
(
*
isc_memalloc_t
)(
void
*
,
size_t
);
typedef
void
(
*
isc_memfree_t
)(
void
*
,
void
*
);
/*
* Define to 0 to remove the names from memory pools. This will save
* about 16 bytes per pool.
*/
#define ISC_MEMPOOL_NAMES 1
#ifdef ISC_MEM_DEBUG
#define isc_mem_get(c, s) __isc_mem_getdebug(c, s, __FILE__, __LINE__)
#define isc_mem_put(c, p, s) __isc_mem_putdebug(c, p, s, __FILE__, __LINE__)
...
...
@@ -138,10 +144,20 @@ isc_mempool_destroy(isc_mempool_t **mpctxp);
* Destroy a memory pool.
*
* Requires:
* mpctxp is a valid pool.
* mpctxp
!= NULL && *mpctxp
is a valid pool.
* The pool has no un"put" allocations outstanding
*/
void
isc_mempool_setname
(
isc_mempool_t
*
mpctx
,
char
*
name
);
/*
* Associate a name with a memory pool. At most 15 characters may be used.
*
* Requires:
* mpctx is a valid pool.
* name != NULL;
*/
void
isc_mempool_associatelock
(
isc_mempool_t
*
mpctx
,
isc_mutex_t
*
lock
);
/*
...
...
lib/isc/mem.c
View file @
78b2f25c
...
...
@@ -46,6 +46,14 @@
#define ISC_MEM_FILL 1
#endif
#ifndef ISC_MEMPOOL_NAMES
/*
* During development it is nice to be able to see names associated with
* memory pools.
*/
#define ISC_MEMPOOL_NAMES 1
#endif
/*
* Types.
*/
...
...
@@ -113,6 +121,10 @@ struct isc_mempool {
unsigned
int
fillcount
;
/* # of items to fetch on each fill */
/* Stats only. */
unsigned
int
gets
;
/* # of requests to this pool */
/* Debugging only. */
#if ISC_MEMPOOL_NAMES
char
name
[
16
];
/* printed name in stats reports */
#endif
};
/* Forward. */
...
...
@@ -547,15 +559,15 @@ isc_mem_stats(isc_mem_t *ctx, FILE *out)
pool
=
ISC_LIST_HEAD
(
ctx
->
pools
);
if
(
pool
!=
NULL
)
{
fprintf
(
out
,
"[Pool statistics]
\n
"
);
fprintf
(
out
,
"%10s %10s %10s %10s %10s %10s %10s %1s
\n
"
,
"size"
,
"maxalloc"
,
"allocated"
,
"freecount"
,
fprintf
(
out
,
"
%15s
%10s %10s %10s %10s %10s %10s %10s %1s
\n
"
,
"name"
,
"size"
,
"maxalloc"
,
"allocated"
,
"freecount"
,
"freemax"
,
"fillcount"
,
"gets"
,
"L"
);
}
while
(
pool
!=
NULL
)
{
fprintf
(
out
,
"%10u %10u %10u %10u %10u %10u %10u %s
\n
"
,
pool
->
size
,
pool
->
maxalloc
,
pool
->
allocated
,
pool
->
freecount
,
pool
->
freemax
,
pool
->
fillcount
,
pool
->
gets
,
fprintf
(
out
,
"
%15s
%10u %10u %10u %10u %10u %10u %10u %s
\n
"
,
pool
->
name
,
pool
->
size
,
pool
->
maxalloc
,
pool
->
allocated
,
pool
->
freecount
,
pool
->
freemax
,
pool
->
fillcount
,
pool
->
gets
,
(
pool
->
lock
==
NULL
?
"N"
:
"Y"
));
pool
=
ISC_LIST_NEXT
(
pool
,
link
);
}
...
...
@@ -838,6 +850,9 @@ isc_mempool_create(isc_mem_t *mctx, size_t size, isc_mempool_t **mpctxp)
mpctx
->
freemax
=
1
;
mpctx
->
fillcount
=
1
;
mpctx
->
gets
=
0
;
#if ISC_MEMPOOL_NAMES
mpctx
->
name
[
0
]
=
0
;
#endif
mpctx
->
items
=
NULL
;
*
mpctxp
=
mpctx
;
...
...
@@ -849,6 +864,26 @@ isc_mempool_create(isc_mem_t *mctx, size_t size, isc_mempool_t **mpctxp)
return
(
ISC_R_SUCCESS
);
}
void
isc_mempool_setname
(
isc_mempool_t
*
mpctx
,
char
*
name
)
{
REQUIRE
(
name
!=
NULL
);
#if ISC_MEMPOOL_NAMES
if
(
mpctx
->
lock
!=
NULL
)
LOCK
(
mpctx
->
lock
);
memset
(
mpctx
->
name
,
0
,
sizeof
(
mpctx
->
name
));
strncpy
(
mpctx
->
name
,
name
,
sizeof
(
mpctx
->
name
)
-
1
);
if
(
mpctx
->
lock
!=
NULL
)
UNLOCK
(
mpctx
->
lock
);
#else
(
void
)
mpctx
;
(
void
)
name
;
#endif
}
void
isc_mempool_destroy
(
isc_mempool_t
**
mpctxp
)
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment