33 #if !defined(DEBUG_THREADLOCALS)
43 #include "asterisk/strings.h"
62 #undef pthread_mutex_t
63 #undef pthread_mutex_lock
64 #undef pthread_mutex_unlock
65 #undef pthread_mutex_init
66 #undef pthread_mutex_destroy
78 void __ast_threadstorage_object_add(
void *key,
size_t len,
const char *file,
const char *
function,
unsigned int line)
80 struct tls_object *to;
88 to->function =
function;
90 to->thread = pthread_self();
97 void __ast_threadstorage_object_remove(
void *key)
99 struct tls_object *to;
103 if (to->key == key) {
114 void __ast_threadstorage_object_replace(
void *key_old,
void *key_new,
size_t len)
116 struct tls_object *to;
120 if (to->key == key_old) {
132 const char *fn = NULL;
134 unsigned int count = 0;
135 struct tls_object *to;
139 e->
command =
"threadstorage show allocations";
141 "Usage: threadstorage show allocations [<file>]\n"
142 " Dumps a list of all thread-specific memory allocations,\n"
143 " optionally limited to those from a specific file\n";
158 if (fn && strcasecmp(to->file, fn))
161 ast_cli(a->
fd,
"%10d bytes allocated in %20s at line %5d of %25s (thread %p)\n",
162 (
int) to->size, to->function, to->line, to->file, (
void *) to->thread);
169 ast_cli(a->
fd,
"%10d bytes allocated in %d allocation%s\n", (
int) len, count, count > 1 ?
"s" :
"");
176 const char *fn = NULL;
178 unsigned int count = 0;
179 struct tls_object *to;
190 e->
command =
"threadstorage show summary";
192 "Usage: threadstorage show summary [<file>]\n"
193 " Summarizes thread-specific memory allocations by file, or optionally\n"
194 " by function, if a file is specified\n";
209 if (fn && strcasecmp(to->file, fn))
213 if ((!fn && (file->name == to->file)) || (fn && (file->name == to->function)))
219 memset(file, 0,
sizeof(*file));
220 file->name = fn ? to->function : to->file;
224 file->len += to->size;
232 count += file->count;
234 ast_cli(a->
fd,
"%10d bytes in %d allocation%ss in function %s\n",
235 (
int) file->len, file->count, file->count > 1 ?
"s" :
"", file->name);
237 ast_cli(a->
fd,
"%10d bytes in %d allocation%s in file %s\n",
238 (
int) file->len, file->count, file->count > 1 ?
"s" :
"", file->name);
242 ast_cli(a->
fd,
"%10d bytes allocated in %d allocation%s\n", (
int) len, count, count > 1 ?
"s" :
"");
248 AST_CLI_DEFINE(handle_cli_threadstorage_show_allocations,
"Display outstanding thread local storage allocations"),
249 AST_CLI_DEFINE(handle_cli_threadstorage_show_summary,
"Summarize outstanding memory allocations")
252 static void threadstorage_shutdown(
void)
#define pthread_mutex_init
#define AST_CLI_DEFINE(fn, txt,...)
Asterisk main include file. File version handling, generic pbx functions.
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
descriptor for a cli entry.
Definitions to aid in the use of thread local storage.
void ast_cli(int fd, const char *fmt,...)
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
#define pthread_mutex_lock
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
int ast_register_atexit(void(*func)(void))
Register a function to be executed before Asterisk exits.
A set of macros to manage forward-linked lists.
static struct ast_cli_entry cli[]
#define AST_LIST_HEAD_NOLOCK_STATIC(name, type)
Defines a structure to be used to hold a list of specified type, statically initialized.
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
#define AST_LIST_ENTRY(type)
Declare a forward link structure inside a list entry.
Prototypes for public functions only of internal interest,.
void threadstorage_init(void)
Standard Command Line Interface.
int ast_cli_register_multiple(struct ast_cli_entry *e, int len)
Register multiple commands.
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
#define pthread_mutex_unlock
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.