[asterisk-commits] logger: Simplify ast callid handling code. (asterisk[master])

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Sep 21 15:15:14 CDT 2016


Anonymous Coward #1000019 has submitted this change and it was merged.

Change subject: logger: Simplify ast_callid handling code.
......................................................................


logger: Simplify ast_callid handling code.

Routines responsible for managing ast_callid's are overly complicated.
This is left-over code from when ast_callid was an AO2 object.  Now that
it is an integer the code can be reduced.

ast_callid handler code no longer prints it's own error message upon failure
to allocate threadstorage as ast_calloc would have already printed a
message.  Debug messages that were printed when TEST_FRAMEWORK was
enabled have been also been removed.

Change-Id: I65a768a78dc6cf3cfa071e97f33ce3dce280258e
---
M main/logger.c
1 file changed, 11 insertions(+), 40 deletions(-)

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



diff --git a/main/logger.c b/main/logger.c
index 9a16dcf..c111182 100644
--- a/main/logger.c
+++ b/main/logger.c
@@ -1762,13 +1762,7 @@
 
 ast_callid ast_create_callid(void)
 {
-	ast_callid call;
-
-	call = ast_atomic_fetchadd_int(&next_unique_callid, +1);
-#ifdef TEST_FRAMEWORK
-	ast_debug(3, "CALL_ID [C-%08x] created by thread.\n", call);
-#endif
-	return call;
+	return ast_atomic_fetchadd_int(&next_unique_callid, +1);
 }
 
 ast_callid ast_read_threadstorage_callid(void)
@@ -1778,7 +1772,6 @@
 	callid = ast_threadstorage_get(&unique_callid, sizeof(*callid));
 
 	return callid ? *callid : 0;
-
 }
 
 int ast_callid_threadassoc_change(ast_callid callid)
@@ -1786,23 +1779,10 @@
 	ast_callid *id = ast_threadstorage_get(&unique_callid, sizeof(*id));
 
 	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);
-#endif
-		*id = 0;
-	}
-
-	if (!(*id) && callid) {
-		*id = callid;
-#ifdef TEST_FRAMEWORK
-		ast_debug(3, "CALL_ID [C-%08x] bound to thread.\n", callid);
-#endif
-	}
+	*id = callid;
 
 	return 0;
 }
@@ -1812,21 +1792,17 @@
 	ast_callid *pointing;
 
 	pointing = ast_threadstorage_get(&unique_callid, sizeof(*pointing));
-	if (!(pointing)) {
-		ast_log(LOG_ERROR, "Failed to allocate thread storage.\n");
+	if (!pointing) {
 		return -1;
 	}
 
-	if (!(*pointing)) {
-		*pointing = callid;
-#ifdef TEST_FRAMEWORK
-		ast_debug(3, "CALL_ID [C-%08x] bound to thread.\n", callid);
-#endif
-	} else {
-		ast_log(LOG_WARNING, "Attempted to ast_callid_threadassoc_add on thread already associated with a callid.\n");
+	if (*pointing) {
+		ast_log(LOG_ERROR, "ast_callid_threadassoc_add(C-%08x) on thread "
+			"already associated with callid [C-%08x].\n", callid, *pointing);
 		return 1;
 	}
 
+	*pointing = callid;
 	return 0;
 }
 
@@ -1835,21 +1811,16 @@
 	ast_callid *pointing;
 
 	pointing = ast_threadstorage_get(&unique_callid, sizeof(*pointing));
-	if (!(pointing)) {
-		ast_log(LOG_ERROR, "Failed to allocate thread storage.\n");
+	if (!pointing) {
 		return -1;
 	}
 
-	if (!(*pointing)) {
-		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);
-#endif
+	if (*pointing) {
 		*pointing = 0;
 		return 0;
 	}
+
+	return -1;
 }
 
 int ast_callid_threadstorage_auto(ast_callid *callid)

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I65a768a78dc6cf3cfa071e97f33ce3dce280258e
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>



More information about the asterisk-commits mailing list