[asterisk-commits] Fix issue with AST THREADSTORAGE RAW when DEBUG THREADLOCALS... (asterisk[certified/13.1])

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Oct 23 06:50:30 CDT 2015


Joshua Colp has submitted this change and it was merged.

Change subject: Fix issue with AST_THREADSTORAGE_RAW when DEBUG_THREADLOCALS is enabled.
......................................................................


Fix issue with AST_THREADSTORAGE_RAW when DEBUG_THREADLOCALS is enabled.

When DEBUG_THREADLOCALS is enabled it causes the threadlocal cleanup to be
called as a function.  This causes a compile error with raw threadstorage as
it uses NULL for cleanup.  This fix uses a macro that provides NULL when
DEBUG_THREADLOCALS is disabled, and replaces the call to "c_cleanup(data);"
with "{};" when DEBUG_THREADLOCALS is enabled.

ASTERISK-24975 #close
Reported by: Ashley Sanders

**** ASTERISK-24975 Change-Id: I3ef7428ee402816d9fcefa1b3b95830c00d5c402

Cherry-pick from v13 with additional definitions of
AST_THREADSTORAGE_RAW(), ast_threadstorage_get_ptr() and
ast_threadstorage_set_ptr() from
commit d01706ce1ee518118456d5673f529204bdac73bb.

Change-Id: I3222102d005f76744561b95a3b97700d82a5ee58
---
M include/asterisk/threadstorage.h
1 file changed, 43 insertions(+), 0 deletions(-)

Approvals:
  Mark Michelson: Looks good to me, but someone else must approve
  Anonymous Coward #1000019: Verified
  Joshua Colp: Looks good to me, approved



diff --git a/include/asterisk/threadstorage.h b/include/asterisk/threadstorage.h
index e3ece8b..4e61f42 100644
--- a/include/asterisk/threadstorage.h
+++ b/include/asterisk/threadstorage.h
@@ -64,6 +64,9 @@
 void __ast_threadstorage_object_add(void *key, size_t len, const char *file, const char *function, unsigned int line);
 void __ast_threadstorage_object_remove(void *key);
 void __ast_threadstorage_object_replace(void *key_old, void *key_new, size_t len);
+#define THREADSTORAGE_RAW_CLEANUP(v) {}
+#else
+#define THREADSTORAGE_RAW_CLEANUP NULL
 #endif /* defined(DEBUG_THREADLOCALS) */
 
 /*!
@@ -84,6 +87,8 @@
 	AST_THREADSTORAGE_CUSTOM_SCOPE(name, NULL, ast_free_ptr,) 
 #define AST_THREADSTORAGE_EXTERNAL(name) \
 	extern struct ast_threadstorage name
+#define AST_THREADSTORAGE_RAW(name) \
+	AST_THREADSTORAGE_CUSTOM_SCOPE(name, NULL, THREADSTORAGE_RAW_CLEANUP,)
 
 /*!
  * \brief Define a thread storage variable, with custom initialization and cleanup
@@ -216,4 +221,42 @@
 #define ast_threadstorage_get(ts, init_size) __ast_threadstorage_get(ts, init_size, __FILE__, __PRETTY_FUNCTION__, __LINE__)
 #endif /* defined(DEBUG_THREADLOCALS) */
 
+/*!
+ * \brief Retrieve a raw pointer from threadstorage.
+ * \param ts Threadstorage object to operate on.
+ *
+ * \return A pointer associated with the current thread, NULL
+ * if no pointer is associated yet.
+ *
+ * \note This should only be used on threadstorage declared
+ * by AST_THREADSTORAGE_RAW unless you really know what
+ * you are doing.
+ */
+AST_INLINE_API(
+void *ast_threadstorage_get_ptr(struct ast_threadstorage *ts),
+{
+	pthread_once(&ts->once, ts->key_init);
+	return pthread_getspecific(ts->key);
+}
+)
+
+/*!
+ * \brief Set a raw pointer from threadstorage.
+ * \param ts Threadstorage object to operate on.
+ *
+ * \retval 0 Success
+ * \retval non-zero Failure
+ *
+ * \note This should only be used on threadstorage declared
+ * by AST_THREADSTORAGE_RAW unless you really know what
+ * you are doing.
+ */
+AST_INLINE_API(
+int ast_threadstorage_set_ptr(struct ast_threadstorage *ts, void *ptr),
+{
+	pthread_once(&ts->once, ts->key_init);
+	return pthread_setspecific(ts->key, ptr);
+}
+)
+
 #endif /* ASTERISK_THREADSTORAGE_H */

-- 
To view, visit https://gerrit.asterisk.org/1451
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I3222102d005f76744561b95a3b97700d82a5ee58
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: certified/13.1
Gerrit-Owner: Richard Mudgett <rmudgett at digium.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Mark Michelson <mmichelson at digium.com>



More information about the asterisk-commits mailing list