diff options
author | markster <markster@f38db490-d61c-443f-a65b-d21fe96a405b> | 2004-11-02 21:56:01 +0000 |
---|---|---|
committer | markster <markster@f38db490-d61c-443f-a65b-d21fe96a405b> | 2004-11-02 21:56:01 +0000 |
commit | 67c5eed4d55aa7f5a73460b3600f8d3107bcbd63 (patch) | |
tree | c0502e9e731f0f02feffcd0065b52e06cd6e6ffb /pbx | |
parent | bd91710f178672aa45e1ca2941a8b0f29e2d651f (diff) |
Fix locking issues
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@4148 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'pbx')
-rwxr-xr-x | pbx/pbx_dundi.c | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/pbx/pbx_dundi.c b/pbx/pbx_dundi.c index 8b583ef71..a9a295323 100755 --- a/pbx/pbx_dundi.c +++ b/pbx/pbx_dundi.c @@ -3183,22 +3183,50 @@ static int dundi_query(struct dundi_transaction *trans) static int discover_transactions(struct dundi_request *dr) { struct dundi_transaction *trans; + ast_mutex_lock(&peerlock); trans = dr->trans; while(trans) { dundi_discover(trans); trans = trans->next; } + ast_mutex_unlock(&peerlock); return 0; } static int precache_transactions(struct dundi_request *dr, struct dundi_mapping *maps, int mapcount, int *expiration, int *foundanswers) { - struct dundi_transaction *trans; + struct dundi_transaction *trans, *transn; + /* Mark all as "in thread" so they don't disappear */ + ast_mutex_lock(&peerlock); trans = dr->trans; while(trans) { - precache_trans(trans, maps, mapcount, expiration, foundanswers); + if (trans->thread) + ast_log(LOG_WARNING, "This shouldn't happen, really...\n"); + trans->thread = 1; trans = trans->next; } + ast_mutex_unlock(&peerlock); + + trans = dr->trans; + while(trans) { + if (!(trans->flags & FLAG_DEAD)) + precache_trans(trans, maps, mapcount, expiration, foundanswers); + trans = trans->next; + } + + /* Cleanup any that got destroyed in the mean time */ + ast_mutex_lock(&peerlock); + trans = dr->trans; + while(trans) { + transn = trans->next; + trans->thread = 0; + if (trans->flags & FLAG_DEAD) { + ast_log(LOG_DEBUG, "Our transaction went away!\n"); + destroy_trans(trans, 0); + } + trans = transn; + } + ast_mutex_unlock(&peerlock); return 0; } |