*/
#define ast_callid_unref(c) ({ ao2_ref(c, -1); (NULL); })
+/*!
+ * \brief Sets what is stored in the thread storage to the given
+ * callid if it does not match what is already there.
+ *
+ * \retval 0 - success
+ * \retval non-zero - failure
+ */
+int ast_callid_threadassoc_change(struct ast_callid *callid);
+
/*!
* \brief Adds a known callid to thread storage of the calling thread
*
static void *autoservice_run(void *ign)
{
+ struct ast_callid *callid = NULL;
struct ast_frame hangup_frame = {
.frametype = AST_FRAME_CONTROL,
.subclass.integer = AST_CONTROL_HANGUP,
int i, x = 0, ms = 50;
struct ast_frame *f = NULL;
struct ast_frame *defer_frame = NULL;
- struct ast_callid *callid = NULL;
AST_LIST_LOCK(&aslist);
continue;
}
- if ((callid = ast_channel_callid(chan))) {
- ast_callid_threadassoc_add(callid);
- }
+ callid = ast_channel_callid(chan);
+ ast_callid_threadassoc_change(callid);
f = ast_read(chan);
} else if (f) {
ast_frfree(f);
}
+ }
- if (callid) {
- ast_callid_threadassoc_remove();
- callid = ast_callid_unref(callid);
- }
+ if (callid) {
+ ast_callid_threadassoc_remove();
+ callid = ast_callid_unref(callid);
}
asthread = AST_PTHREADT_NULL;
}
call->call_identifier = ast_atomic_fetchadd_int(&next_unique_callid, +1);
+#ifdef TEST_FRAMEWORK
ast_debug(3, "CALL_ID [C-%08x] created by thread.\n", call->call_identifier);
+#endif
return call;
}
}
+int ast_callid_threadassoc_change(struct ast_callid *callid)
+{
+ struct ast_callid **id =
+ ast_threadstorage_get(&unique_callid, sizeof(struct ast_callid **));
+
+ if (!id) {
+ ast_log(LOG_ERROR, "Failed to allocate thread storage.\n");
+ return -1;
+ }
+
+ if (*id && (*id != callid)) {
+#ifdef TEST_FRAMEWORK
+ ast_debug(3, "CALL_ID [C-%08x] being removed from thread.\n", (*id)->call_identifier);
+#endif
+ *id = ast_callid_unref(*id);
+ *id = NULL;
+ }
+
+ if (!(*id) && callid) {
+ /* callid will be unreffed at thread destruction */
+ ast_callid_ref(callid);
+ *id = callid;
+#ifdef TEST_FRAMEWORK
+ ast_debug(3, "CALL_ID [C-%08x] bound to thread.\n", callid->call_identifier);
+#endif
+ }
+
+ return 0;
+}
+
int ast_callid_threadassoc_add(struct ast_callid *callid)
{
struct ast_callid **pointing;
/* callid will be unreffed at thread destruction */
ast_callid_ref(callid);
*pointing = callid;
+#ifdef TEST_FRAMEWORK
ast_debug(3, "CALL_ID [C-%08x] bound to thread.\n", callid->call_identifier);
+#endif
} else {
ast_log(LOG_WARNING, "Attempted to ast_callid_threadassoc_add on thread already associated with a callid.\n");
return 1;
ast_log(LOG_ERROR, "Tried to clean callid thread storage with no callid in thread storage.\n");
return -1;
} else {
+#ifdef TEST_FRAMEWORK
ast_debug(3, "CALL_ID [C-%08x] being removed from thread.\n", (*pointing)->call_identifier);
+#endif
*pointing = ast_callid_unref(*pointing);
return 0;
}