Skip to content
Snippets Groups Projects
Commit 8a889843 authored by Joshua Colp's avatar Joshua Colp
Browse files

Switch the devicestate thread to operate the same way as the logging thread....

Switch the devicestate thread to operate the same way as the logging thread. Pops all entries off the list to be processed, resets the list back to a clean state, and processes each entry. The thread won't have to acquire the list lock again until it checks to see if there are more to process.


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@53112 65c4cc65-6c06-0410-ace0-fbb531ad65f3
parent ae64c71d
No related branches found
No related tags found
No related merge requests found
...@@ -400,9 +400,7 @@ static int __ast_device_state_changed_literal(char *buf) ...@@ -400,9 +400,7 @@ static int __ast_device_state_changed_literal(char *buf)
strcpy(change->device, device); strcpy(change->device, device);
AST_LIST_LOCK(&state_changes); AST_LIST_LOCK(&state_changes);
AST_LIST_INSERT_TAIL(&state_changes, change, list); AST_LIST_INSERT_TAIL(&state_changes, change, list);
if (AST_LIST_FIRST(&state_changes) == change) ast_cond_signal(&change_pending);
/* the list was empty, signal the thread */
ast_cond_signal(&change_pending);
AST_LIST_UNLOCK(&state_changes); AST_LIST_UNLOCK(&state_changes);
} }
...@@ -431,22 +429,22 @@ int ast_device_state_changed(const char *fmt, ...) ...@@ -431,22 +429,22 @@ int ast_device_state_changed(const char *fmt, ...)
/*! \brief Go through the dev state change queue and update changes in the dev state thread */ /*! \brief Go through the dev state change queue and update changes in the dev state thread */
static void *do_devstate_changes(void *data) static void *do_devstate_changes(void *data)
{ {
struct state_change *cur; struct state_change *next, *current;
AST_LIST_LOCK(&state_changes);
for (;;) { for (;;) {
/* the list lock will _always_ be held at this point in the loop */ /* This basically pops off any state change entries, resets the list back to NULL, unlocks, and processes each state change */
cur = AST_LIST_REMOVE_HEAD(&state_changes, list); AST_LIST_LOCK(&state_changes);
if (cur) { if (AST_LIST_EMPTY(&state_changes))
/* we got an entry, so unlock the list while we process it */
AST_LIST_UNLOCK(&state_changes);
do_state_change(cur->device);
free(cur);
AST_LIST_LOCK(&state_changes);
} else {
/* there was no entry, so atomically unlock the list and wait for
the condition to be signalled (returns with the lock held) */
ast_cond_wait(&change_pending, &state_changes.lock); ast_cond_wait(&change_pending, &state_changes.lock);
next = AST_LIST_FIRST(&state_changes);
AST_LIST_HEAD_INIT_NOLOCK(&state_changes);
AST_LIST_UNLOCK(&state_changes);
/* Process each state change */
while ((current = next)) {
next = AST_LIST_NEXT(current, list);
do_state_change(current->device);
free(current);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment