mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-16 14:58:25 +00:00
Merged revisions 98960 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r98960 | file | 2008-01-16 11:08:24 -0400 (Wed, 16 Jan 2008) | 6 lines Introduce a lock into the dialing API that protects it when destroying the structure. (closes issue #11687) Reported by: callguy Patches: 11687.diff uploaded by file (license 11) ........ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@98961 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
15
main/dial.c
15
main/dial.c
@@ -48,6 +48,7 @@ struct ast_dial {
|
|||||||
ast_dial_state_callback state_callback; /*!< Status callback */
|
ast_dial_state_callback state_callback; /*!< Status callback */
|
||||||
AST_LIST_HEAD_NOLOCK(, ast_dial_channel) channels; /*!< Channels being dialed */
|
AST_LIST_HEAD_NOLOCK(, ast_dial_channel) channels; /*!< Channels being dialed */
|
||||||
pthread_t thread; /*!< Thread (if running in async) */
|
pthread_t thread; /*!< Thread (if running in async) */
|
||||||
|
ast_mutex_t lock; /*! Lock to protect the thread information above */
|
||||||
};
|
};
|
||||||
|
|
||||||
/*! \brief Dialing channel structure. Contains per-channel dialing options, asterisk channel, and more! */
|
/*! \brief Dialing channel structure. Contains per-channel dialing options, asterisk channel, and more! */
|
||||||
@@ -149,10 +150,12 @@ static void answer_exec_run(struct ast_dial *dial, struct ast_dial_channel *dial
|
|||||||
pbx_exec(chan, ast_app, args);
|
pbx_exec(chan, ast_app, args);
|
||||||
|
|
||||||
/* If another thread is not taking over hang up the channel */
|
/* If another thread is not taking over hang up the channel */
|
||||||
|
ast_mutex_lock(&dial->lock);
|
||||||
if (dial->thread != AST_PTHREADT_STOP) {
|
if (dial->thread != AST_PTHREADT_STOP) {
|
||||||
ast_hangup(chan);
|
ast_hangup(chan);
|
||||||
dial_channel->owner = NULL;
|
dial_channel->owner = NULL;
|
||||||
}
|
}
|
||||||
|
ast_mutex_unlock(&dial->lock);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -209,6 +212,9 @@ struct ast_dial *ast_dial_create(void)
|
|||||||
dial->timeout = -1;
|
dial->timeout = -1;
|
||||||
dial->actual_timeout = -1;
|
dial->actual_timeout = -1;
|
||||||
|
|
||||||
|
/* Can't forget about the lock */
|
||||||
|
ast_mutex_init(&dial->lock);
|
||||||
|
|
||||||
return dial;
|
return dial;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -739,6 +745,9 @@ enum ast_dial_result ast_dial_join(struct ast_dial *dial)
|
|||||||
/* Record thread */
|
/* Record thread */
|
||||||
thread = dial->thread;
|
thread = dial->thread;
|
||||||
|
|
||||||
|
/* Boom, commence locking */
|
||||||
|
ast_mutex_lock(&dial->lock);
|
||||||
|
|
||||||
/* Stop the thread */
|
/* Stop the thread */
|
||||||
dial->thread = AST_PTHREADT_STOP;
|
dial->thread = AST_PTHREADT_STOP;
|
||||||
|
|
||||||
@@ -753,6 +762,9 @@ enum ast_dial_result ast_dial_join(struct ast_dial *dial)
|
|||||||
pthread_kill(thread, SIGURG);
|
pthread_kill(thread, SIGURG);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Yay done with it */
|
||||||
|
ast_mutex_unlock(&dial->lock);
|
||||||
|
|
||||||
/* Finally wait for the thread to exit */
|
/* Finally wait for the thread to exit */
|
||||||
pthread_join(thread, NULL);
|
pthread_join(thread, NULL);
|
||||||
|
|
||||||
@@ -828,6 +840,9 @@ int ast_dial_destroy(struct ast_dial *dial)
|
|||||||
dial->options[i] = NULL;
|
dial->options[i] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Lock be gone! */
|
||||||
|
ast_mutex_destroy(&dial->lock);
|
||||||
|
|
||||||
/* Free structure */
|
/* Free structure */
|
||||||
ast_free(dial);
|
ast_free(dial);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user