Skip to content
Snippets Groups Projects
Commit aeb752fc authored by Russell Bryant's avatar Russell Bryant
Browse files

Merged revisions 91192 via svnmerge from

https://origsvn.digium.com/svn/asterisk/branches/1.4

........
r91192 | russell | 2007-12-05 11:31:42 -0600 (Wed, 05 Dec 2007) | 10 lines

Make the lock in the threadstorage debugging code untracked to avoid a deadlock
on thread destruction.

(closes issue #11207)
Reported by: ys
Patches:
      threadstorage.c.diff uploaded by ys (license 281)

Also fixes an open bug report: (closes issue #11446)

........


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@91197 65c4cc65-6c06-0410-ace0-fbb531ad65f3
parent f82c42a2
No related branches found
No related tags found
No related merge requests found
...@@ -52,7 +52,9 @@ struct tls_object { ...@@ -52,7 +52,9 @@ struct tls_object {
AST_LIST_ENTRY(tls_object) entry; AST_LIST_ENTRY(tls_object) entry;
}; };
static AST_RWLIST_HEAD_STATIC(tls_objects, tls_object); static AST_LIST_HEAD_NOLOCK_STATIC(tls_objects, tls_object);
AST_MUTEX_DEFINE_STATIC_NOTRACKING(threadstoragelock);
void __ast_threadstorage_object_add(void *key, size_t len, const char *file, const char *function, unsigned int line) void __ast_threadstorage_object_add(void *key, size_t len, const char *file, const char *function, unsigned int line)
{ {
...@@ -68,16 +70,16 @@ void __ast_threadstorage_object_add(void *key, size_t len, const char *file, con ...@@ -68,16 +70,16 @@ void __ast_threadstorage_object_add(void *key, size_t len, const char *file, con
to->line = line; to->line = line;
to->thread = pthread_self(); to->thread = pthread_self();
AST_RWLIST_WRLOCK(&tls_objects); ast_mutex_lock(&threadstoragelock);
AST_LIST_INSERT_TAIL(&tls_objects, to, entry); AST_LIST_INSERT_TAIL(&tls_objects, to, entry);
AST_RWLIST_UNLOCK(&tls_objects); ast_mutex_unlock(&threadstoragelock);
} }
void __ast_threadstorage_object_remove(void *key) void __ast_threadstorage_object_remove(void *key)
{ {
struct tls_object *to; struct tls_object *to;
AST_RWLIST_WRLOCK(&tls_objects); ast_mutex_lock(&threadstoragelock);
AST_LIST_TRAVERSE_SAFE_BEGIN(&tls_objects, to, entry) { AST_LIST_TRAVERSE_SAFE_BEGIN(&tls_objects, to, entry) {
if (to->key == key) { if (to->key == key) {
AST_LIST_REMOVE_CURRENT(entry); AST_LIST_REMOVE_CURRENT(entry);
...@@ -85,7 +87,7 @@ void __ast_threadstorage_object_remove(void *key) ...@@ -85,7 +87,7 @@ void __ast_threadstorage_object_remove(void *key)
} }
} }
AST_LIST_TRAVERSE_SAFE_END; AST_LIST_TRAVERSE_SAFE_END;
AST_RWLIST_UNLOCK(&tls_objects); ast_mutex_unlock(&threadstoragelock);
if (to) if (to)
ast_free(to); ast_free(to);
} }
...@@ -94,7 +96,7 @@ void __ast_threadstorage_object_replace(void *key_old, void *key_new, size_t len ...@@ -94,7 +96,7 @@ void __ast_threadstorage_object_replace(void *key_old, void *key_new, size_t len
{ {
struct tls_object *to; struct tls_object *to;
AST_RWLIST_WRLOCK(&tls_objects); ast_mutex_lock(&threadstoragelock);
AST_LIST_TRAVERSE_SAFE_BEGIN(&tls_objects, to, entry) { AST_LIST_TRAVERSE_SAFE_BEGIN(&tls_objects, to, entry) {
if (to->key == key_old) { if (to->key == key_old) {
to->key = key_new; to->key = key_new;
...@@ -103,7 +105,7 @@ void __ast_threadstorage_object_replace(void *key_old, void *key_new, size_t len ...@@ -103,7 +105,7 @@ void __ast_threadstorage_object_replace(void *key_old, void *key_new, size_t len
} }
} }
AST_LIST_TRAVERSE_SAFE_END; AST_LIST_TRAVERSE_SAFE_END;
AST_RWLIST_UNLOCK(&tls_objects); ast_mutex_unlock(&threadstoragelock);
} }
static char *handle_cli_threadstorage_show_allocations(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) static char *handle_cli_threadstorage_show_allocations(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
...@@ -131,7 +133,7 @@ static char *handle_cli_threadstorage_show_allocations(struct ast_cli_entry *e, ...@@ -131,7 +133,7 @@ static char *handle_cli_threadstorage_show_allocations(struct ast_cli_entry *e,
if (a->argc > 3) if (a->argc > 3)
fn = a->argv[3]; fn = a->argv[3];
AST_RWLIST_RDLOCK(&tls_objects); ast_mutex_lock(&threadstoragelock);
AST_LIST_TRAVERSE(&tls_objects, to, entry) { AST_LIST_TRAVERSE(&tls_objects, to, entry) {
if (fn && strcasecmp(to->file, fn)) if (fn && strcasecmp(to->file, fn))
...@@ -143,7 +145,7 @@ static char *handle_cli_threadstorage_show_allocations(struct ast_cli_entry *e, ...@@ -143,7 +145,7 @@ static char *handle_cli_threadstorage_show_allocations(struct ast_cli_entry *e,
count++; count++;
} }
AST_RWLIST_UNLOCK(&tls_objects); ast_mutex_unlock(&threadstoragelock);
ast_cli(a->fd, "%10d bytes allocated in %d allocation%s\n", (int) len, count, count > 1 ? "s" : ""); ast_cli(a->fd, "%10d bytes allocated in %d allocation%s\n", (int) len, count, count > 1 ? "s" : "");
...@@ -182,7 +184,7 @@ static char *handle_cli_threadstorage_show_summary(struct ast_cli_entry *e, int ...@@ -182,7 +184,7 @@ static char *handle_cli_threadstorage_show_summary(struct ast_cli_entry *e, int
if (a->argc > 3) if (a->argc > 3)
fn = a->argv[3]; fn = a->argv[3];
AST_RWLIST_RDLOCK(&tls_objects); ast_mutex_lock(&threadstoragelock);
AST_LIST_TRAVERSE(&tls_objects, to, entry) { AST_LIST_TRAVERSE(&tls_objects, to, entry) {
if (fn && strcasecmp(to->file, fn)) if (fn && strcasecmp(to->file, fn))
...@@ -204,7 +206,7 @@ static char *handle_cli_threadstorage_show_summary(struct ast_cli_entry *e, int ...@@ -204,7 +206,7 @@ static char *handle_cli_threadstorage_show_summary(struct ast_cli_entry *e, int
file->count++; file->count++;
} }
AST_RWLIST_UNLOCK(&tls_objects); ast_mutex_unlock(&threadstoragelock);
AST_LIST_TRAVERSE(&file_summary, file, entry) { AST_LIST_TRAVERSE(&file_summary, file, entry) {
len += file->len; len += file->len;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment