Assist proper thread synchronization when stopping the logger thread.
authorMark Michelson <mmichelson@digium.com>
Mon, 16 Feb 2009 18:25:57 +0000 (18:25 +0000)
committerMark Michelson <mmichelson@digium.com>
Mon, 16 Feb 2009 18:25:57 +0000 (18:25 +0000)
I was finding that on my dev box, occasionally attempting to "stop now" in
trunk would cause Asterisk to hang. I traced this to the fact that the logger
thread was waiting on a condition which had already been signalled. The logger
thread also need to be sure to check the value of the close_logger_thread variable.

The close_logger_thread variable is only checked when the list of logmessages is empty.
This allows for the logger thread to print and free any pending messages before exiting.

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@176174 65c4cc65-6c06-0410-ace0-fbb531ad65f3

main/logger.c

index 23b823e..1635489 100644 (file)
@@ -973,8 +973,13 @@ static void *logger_thread(void *data)
        for (;;) {
                /* We lock the message list, and see if any message exists... if not we wait on the condition to be signalled */
                AST_LIST_LOCK(&logmsgs);
-               if (AST_LIST_EMPTY(&logmsgs))
-                       ast_cond_wait(&logcond, &logmsgs.lock);
+               if (AST_LIST_EMPTY(&logmsgs)) {
+                       if (close_logger_thread) {
+                               break;
+                       } else {
+                               ast_cond_wait(&logcond, &logmsgs.lock);
+                       }
+               }
                next = AST_LIST_FIRST(&logmsgs);
                AST_LIST_HEAD_INIT_NOLOCK(&logmsgs);
                AST_LIST_UNLOCK(&logmsgs);