logger: Simplify ast_callid handling code.
authorCorey Farrell <git@cfware.com>
Tue, 16 Aug 2016 20:21:33 +0000 (16:21 -0400)
committerCorey Farrell <git@cfware.com>
Tue, 20 Sep 2016 23:25:16 +0000 (18:25 -0500)
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

main/logger.c

index 9a16dcf..c111182 100644 (file)
@@ -1762,13 +1762,7 @@ void ast_callid_strnprint(char *buffer, size_t buffer_size, ast_callid callid)
 
 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 @@ ast_callid ast_read_threadstorage_callid(void)
        callid = ast_threadstorage_get(&unique_callid, sizeof(*callid));
 
        return callid ? *callid : 0;
-
 }
 
 int ast_callid_threadassoc_change(ast_callid callid)
@@ -1786,23 +1779,10 @@ int ast_callid_threadassoc_change(ast_callid callid)
        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 @@ int ast_callid_threadassoc_add(ast_callid callid)
        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 @@ int ast_callid_threadassoc_remove(void)
        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)