diff options
author | Richard Mudgett <rmudgett@digium.com> | 2012-02-28 18:46:34 +0000 |
---|---|---|
committer | Richard Mudgett <rmudgett@digium.com> | 2012-02-28 18:46:34 +0000 |
commit | 85ea4277f1e90a11cc7b80c3fad681598eb3650b (patch) | |
tree | 7036c9c033648e9f833652f29075e69e14c29b95 | |
parent | 565f411868288d911b63944e4c8410b8e2951b7b (diff) |
Convert struct ast_tcptls_session_instance to finally use the ao2 object lock.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@357317 65c4cc65-6c06-0410-ace0-fbb531ad65f3
-rw-r--r-- | channels/chan_sip.c | 22 | ||||
-rw-r--r-- | include/asterisk/tcptls.h | 2 | ||||
-rw-r--r-- | main/tcptls.c | 13 |
3 files changed, 13 insertions, 24 deletions
diff --git a/channels/chan_sip.c b/channels/chan_sip.c index e2dcafc27..046ef5757 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -2440,7 +2440,7 @@ static int sip_tcptls_write(struct ast_tcptls_session_instance *tcptls_session, return XMIT_ERROR; } - ast_mutex_lock(&tcptls_session->lock); + ao2_lock(tcptls_session); if ((tcptls_session->fd == -1) || !(th = ao2_t_find(threadt, &tmp, OBJ_POINTER, "ao2_find, getting sip_threadinfo in tcp helper thread")) || @@ -2467,7 +2467,7 @@ static int sip_tcptls_write(struct ast_tcptls_session_instance *tcptls_session, } ao2_unlock(th); - ast_mutex_unlock(&tcptls_session->lock); + ao2_unlock(tcptls_session); ao2_t_ref(th, -1, "In sip_tcptls_write, unref threadinfo object after finding it"); return res; @@ -2478,7 +2478,7 @@ tcptls_write_setup_error: if (packet) { ao2_t_ref(packet, -1, "could not allocate packet's data"); } - ast_mutex_unlock(&tcptls_session->lock); + ao2_unlock(tcptls_session); return XMIT_ERROR; } @@ -2692,9 +2692,9 @@ static void *_sip_tcp_helper_thread(struct ast_tcptls_session_instance *tcptls_s } } - ast_mutex_lock(&tcptls_session->lock); + ao2_lock(tcptls_session); if (!fgets(buf, sizeof(buf), tcptls_session->f)) { - ast_mutex_unlock(&tcptls_session->lock); + ao2_unlock(tcptls_session); if (after_poll) { goto cleanup; } else { @@ -2702,7 +2702,7 @@ static void *_sip_tcp_helper_thread(struct ast_tcptls_session_instance *tcptls_s continue; } } - ast_mutex_unlock(&tcptls_session->lock); + ao2_unlock(tcptls_session); after_poll = 0; if (me->stop) { goto cleanup; @@ -2742,9 +2742,9 @@ static void *_sip_tcp_helper_thread(struct ast_tcptls_session_instance *tcptls_s } } - ast_mutex_lock(&tcptls_session->lock); + ao2_lock(tcptls_session); if (!(bytes_read = fread(buf, 1, MIN(sizeof(buf) - 1, cl), tcptls_session->f))) { - ast_mutex_unlock(&tcptls_session->lock); + ao2_unlock(tcptls_session); if (after_poll) { goto cleanup; } else { @@ -2753,7 +2753,7 @@ static void *_sip_tcp_helper_thread(struct ast_tcptls_session_instance *tcptls_s } } buf[bytes_read] = '\0'; - ast_mutex_unlock(&tcptls_session->lock); + ao2_unlock(tcptls_session); after_poll = 0; if (me->stop) { goto cleanup; @@ -2823,10 +2823,10 @@ cleanup: } if (tcptls_session) { - ast_mutex_lock(&tcptls_session->lock); + ao2_lock(tcptls_session); ast_tcptls_close_session_file(tcptls_session); tcptls_session->parent = NULL; - ast_mutex_unlock(&tcptls_session->lock); + ao2_unlock(tcptls_session); ao2_ref(tcptls_session, -1); tcptls_session = NULL; diff --git a/include/asterisk/tcptls.h b/include/asterisk/tcptls.h index c60501397..ba6ac12d9 100644 --- a/include/asterisk/tcptls.h +++ b/include/asterisk/tcptls.h @@ -155,8 +155,6 @@ struct ast_tcptls_session_instance { int client; struct ast_sockaddr remote_address; struct ast_tcptls_session_args *parent; - /*! \todo XXX Why do we still use this lock when this struct is allocated as an ao2 object which has its own lock? */ - ast_mutex_t lock; }; #if defined(HAVE_FUNOPEN) diff --git a/main/tcptls.c b/main/tcptls.c index 8210839c0..48d8ff75d 100644 --- a/main/tcptls.c +++ b/main/tcptls.c @@ -131,12 +131,6 @@ HOOK_T ast_tcptls_server_write(struct ast_tcptls_session_instance *tcptls_sessio return write(tcptls_session->fd, buf, count); } -static void session_instance_destructor(void *obj) -{ - struct ast_tcptls_session_instance *i = obj; - ast_mutex_destroy(&i->lock); -} - /*! \brief * creates a FILE * from the fd passed by the accept thread. * This operation is potentially expensive (certificate verification), @@ -285,7 +279,7 @@ void *ast_tcptls_server_root(void *data) } continue; } - tcptls_session = ao2_alloc(sizeof(*tcptls_session), session_instance_destructor); + tcptls_session = ao2_alloc(sizeof(*tcptls_session), NULL); if (!tcptls_session) { ast_log(LOG_WARNING, "No memory for new session: %s\n", strerror(errno)); if (close(fd)) { @@ -294,8 +288,6 @@ void *ast_tcptls_server_root(void *data) continue; } - ast_mutex_init(&tcptls_session->lock); - flags = fcntl(fd, F_GETFL); fcntl(fd, F_SETFL, flags & ~O_NONBLOCK); tcptls_session->fd = fd; @@ -477,11 +469,10 @@ struct ast_tcptls_session_instance *ast_tcptls_client_create(struct ast_tcptls_s } } - if (!(tcptls_session = ao2_alloc(sizeof(*tcptls_session), session_instance_destructor))) { + if (!(tcptls_session = ao2_alloc(sizeof(*tcptls_session), NULL))) { goto error; } - ast_mutex_init(&tcptls_session->lock); tcptls_session->client = 1; tcptls_session->fd = desc->accept_fd; tcptls_session->parent = desc; |