Make ast_sched_report() and ast_sched_dump() thread safe.
authorRussell Bryant <russell@russellbryant.com>
Sun, 15 Feb 2009 21:27:33 +0000 (21:27 +0000)
committerRussell Bryant <russell@russellbryant.com>
Sun, 15 Feb 2009 21:27:33 +0000 (21:27 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@175882 65c4cc65-6c06-0410-ace0-fbb531ad65f3

include/asterisk/sched.h
main/sched.c

index 564453a..1a6e3f0 100644 (file)
@@ -257,7 +257,7 @@ int ast_sched_runq(struct sched_context *con);
  * Debugging: Dump the contents of the scheduler to stderr
  * \param con Context to dump
  */
-void ast_sched_dump(const struct sched_context *con);
+void ast_sched_dump(struct sched_context *con);
 
 /*! \brief Returns the number of seconds before an event takes place
  * \param con Context to use
index e6fe054..6d997ba 100644 (file)
@@ -536,6 +536,7 @@ void ast_sched_report(struct sched_context *con, struct ast_str **buf, struct as
        
        ast_str_set(buf, 0, " Highwater = %d\n schedcnt = %d\n", con->highwater, con->schedcnt);
 
+       ast_mutex_lock(&con->lock);
        AST_DLLIST_TRAVERSE(&con->schedq, cur, list) {
                /* match the callback to the cblist */
                for (i = 0; i < cbnames->numassocs; i++) {
@@ -549,6 +550,7 @@ void ast_sched_report(struct sched_context *con, struct ast_str **buf, struct as
                        countlist[cbnames->numassocs]++;
                }
        }
+       ast_mutex_unlock(&con->lock);
 
        for (i = 0; i < cbnames->numassocs; i++) {
                ast_str_append(buf, 0, "    %s : %d\n", cbnames->list[i], countlist[i]);
@@ -558,7 +560,7 @@ void ast_sched_report(struct sched_context *con, struct ast_str **buf, struct as
 }
        
 /*! \brief Dump the contents of the scheduler to LOG_DEBUG */
-void ast_sched_dump(const struct sched_context *con)
+void ast_sched_dump(struct sched_context *con)
 {
        struct sched *q;
        struct timeval when = ast_tvnow();
@@ -571,6 +573,7 @@ void ast_sched_dump(const struct sched_context *con)
        ast_debug(1, "=============================================================\n");
        ast_debug(1, "|ID    Callback          Data              Time  (sec:ms)   |\n");
        ast_debug(1, "+-----+-----------------+-----------------+-----------------+\n");
+       ast_mutex_lock(&con->lock);
        AST_DLLIST_TRAVERSE(&con->schedq, q, list) {
                struct timeval delta = ast_tvsub(q->when, when);
 
@@ -581,8 +584,8 @@ void ast_sched_dump(const struct sched_context *con)
                        (long)delta.tv_sec,
                        (long int)delta.tv_usec);
        }
+       ast_mutex_unlock(&con->lock);
        ast_debug(1, "=============================================================\n");
-       
 }
 
 /*! \brief