[svn-commits] russell: branch russell/ast_verbose_threadstorage r38409 - /team/russell/ast_...

svn-commits at lists.digium.com svn-commits at lists.digium.com
Fri Jul 28 01:07:55 MST 2006


Author: russell
Date: Fri Jul 28 03:07:54 2006
New Revision: 38409

URL: http://svn.digium.com/view/asterisk?rev=38409&view=rev
Log:
reduce some code duplication and rename some variables

Modified:
    team/russell/ast_verbose_threadstorage/include/asterisk/threadstorage.h

Modified: team/russell/ast_verbose_threadstorage/include/asterisk/threadstorage.h
URL: http://svn.digium.com/view/asterisk/team/russell/ast_verbose_threadstorage/include/asterisk/threadstorage.h?rev=38409&r1=38408&r2=38409&view=diff
==============================================================================
--- team/russell/ast_verbose_threadstorage/include/asterisk/threadstorage.h (original)
+++ team/russell/ast_verbose_threadstorage/include/asterisk/threadstorage.h Fri Jul 28 03:07:54 2006
@@ -82,23 +82,21 @@
 )
 
 AST_INLINE_API(
-struct ast_dynamic_str *ast_dynamic_str_threadget(struct ast_threadstorage *threadstorage,
+struct ast_dynamic_str *ast_dynamic_str_threadget(struct ast_threadstorage *ts,
 	size_t init_len),
 {
 	struct ast_dynamic_str *buf;
 
-	pthread_once(&threadstorage->once, threadstorage->key_init);
-	if (!(buf = pthread_getspecific(threadstorage->key))) {
-		if (!(buf = ast_dynamic_str_create(init_len)))
-			return NULL;
-		pthread_setspecific(threadstorage->key, buf);
-	}
+	if (!(buf = ast_threadstorage_get(ts, sizeof(*buf) + init_len)))
+		return NULL;
+	
+	if (!buf->len)
+		buf->len = init_len;
 
 	return buf;
 }
 )
 
-/* A dirty hack. */
 enum {
 	AST_DYNSTR_BUILD_FAILED = -1,
 	AST_DYNSTR_BUILD_RETRY = -2
@@ -106,7 +104,7 @@
 
 AST_INLINE_API(
 int ast_dynamic_str_threadbuild_va(struct ast_dynamic_str **buf, size_t max_len,
-	struct ast_threadstorage *threadstorage, const char *fmt, va_list ap),
+	struct ast_threadstorage *ts, const char *fmt, va_list ap),
 {
 	int res;
 
@@ -116,8 +114,8 @@
 		if (!(*buf = ast_realloc(*buf, ((*buf)->len * 2) + sizeof(*(*buf)))))
 			return AST_DYNSTR_BUILD_FAILED;
 		(*buf)->len *= 2;
-		if (threadstorage)
-			pthread_setspecific(threadstorage->key, *buf);
+		if (ts)
+			pthread_setspecific(ts->key, *buf);
 		return AST_DYNSTR_BUILD_RETRY;
 	}
 
@@ -127,13 +125,13 @@
 
 AST_INLINE_API(
 int ast_dynamic_str_threadbuild(struct ast_dynamic_str **buf, size_t max_len, 
-	struct ast_threadstorage *threadstorage, const char *fmt, ...),
+	struct ast_threadstorage *ts, const char *fmt, ...),
 {
 	int res;
 	va_list ap;
 
 	va_start(ap, fmt);
-	while ((res = ast_dynamic_str_threadbuild_va(buf, max_len, threadstorage, fmt, ap)) == AST_DYNSTR_BUILD_RETRY) {
+	while ((res = ast_dynamic_str_threadbuild_va(buf, max_len, ts, fmt, ap)) == AST_DYNSTR_BUILD_RETRY) {
 		va_end(ap);
 		va_start(ap, fmt);
 	}



More information about the svn-commits mailing list