[asterisk-commits] russell: branch
russell/ast_verbose_threadstorage r38412 - /team/russell/ast_...
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Fri Jul 28 01:22:29 MST 2006
Author: russell
Date: Fri Jul 28 03:22:29 2006
New Revision: 38412
URL: http://svn.digium.com/view/asterisk?rev=38412&view=rev
Log:
convert ast_verbose to the new interface
Modified:
team/russell/ast_verbose_threadstorage/logger.c
Modified: team/russell/ast_verbose_threadstorage/logger.c
URL: http://svn.digium.com/view/asterisk/team/russell/ast_verbose_threadstorage/logger.c?rev=38412&r1=38411&r2=38412&view=diff
==============================================================================
--- team/russell/ast_verbose_threadstorage/logger.c (original)
+++ team/russell/ast_verbose_threadstorage/logger.c Fri Jul 28 03:22:29 2006
@@ -68,8 +68,7 @@
#include "asterisk/cli.h"
#include "asterisk/utils.h"
#include "asterisk/manager.h"
-
-#define MAX_MSG_QUEUE 200
+#include "asterisk/threadstorage.h"
#if defined(__linux__) && !defined(__NR_gettid)
#include <asm/unistd.h>
@@ -135,8 +134,7 @@
COLOR_BRGREEN
};
-static pthread_once_t verbose_buf_once = PTHREAD_ONCE_INIT;
-static pthread_key_t verbose_buf_key;
+AST_THREADSTORAGE(verbose_buf, verbose_buf_init);
#define VERBOSE_BUF_INIT_SIZE 128
@@ -913,41 +911,20 @@
#endif
}
-static void verbose_buf_key_create(void)
-{
- pthread_key_create(&verbose_buf_key, FREE);
-}
-
void ast_verbose(const char *fmt, ...)
{
struct verb *v;
+ struct ast_dynamic_str *buf;
int res;
va_list ap;
- struct {
- size_t len;
- char str[0];
- } *buf;
-
- pthread_once(&verbose_buf_once, verbose_buf_key_create);
- if (!(buf = pthread_getspecific(verbose_buf_key))) {
- if (!(buf = ast_malloc(VERBOSE_BUF_INIT_SIZE + sizeof(*buf))))
- return;
- buf->len = VERBOSE_BUF_INIT_SIZE;
- pthread_setspecific(verbose_buf_key, buf);
- }
+
+ if (!(buf = ast_dynamic_str_threadget(&verbose_buf, VERBOSE_BUF_INIT_SIZE)))
+ return;
va_start(ap, fmt);
- res = vsnprintf(buf->str, buf->len, fmt, ap);
- while (res >= buf->len) {
- if (!(buf = ast_realloc(buf, (buf->len * 2) + sizeof(*buf)))) {
- va_end(ap);
- return;
- }
- buf->len *= 2;
- pthread_setspecific(verbose_buf_key, buf);
+ while ((res = ast_dynamic_str_threadbuild_va(&buf, 0, &verbose_buf, fmt, ap)) == AST_DYNSTR_BUILD_RETRY) {
va_end(ap);
va_start(ap, fmt);
- res = vsnprintf(buf->str, buf->len, fmt, ap);
}
va_end(ap);
More information about the asterisk-commits
mailing list