Skip to content
Snippets Groups Projects
Commit 85ea4277 authored by Richard Mudgett's avatar Richard Mudgett
Browse files

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
parent 565f4118
Branches
Tags
No related merge requests found
...@@ -2440,7 +2440,7 @@ static int sip_tcptls_write(struct ast_tcptls_session_instance *tcptls_session, ...@@ -2440,7 +2440,7 @@ static int sip_tcptls_write(struct ast_tcptls_session_instance *tcptls_session,
return XMIT_ERROR; return XMIT_ERROR;
} }
   
ast_mutex_lock(&tcptls_session->lock); ao2_lock(tcptls_session);
   
if ((tcptls_session->fd == -1) || if ((tcptls_session->fd == -1) ||
!(th = ao2_t_find(threadt, &tmp, OBJ_POINTER, "ao2_find, getting sip_threadinfo in tcp helper thread")) || !(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, ...@@ -2467,7 +2467,7 @@ static int sip_tcptls_write(struct ast_tcptls_session_instance *tcptls_session,
} }
ao2_unlock(th); 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"); ao2_t_ref(th, -1, "In sip_tcptls_write, unref threadinfo object after finding it");
return res; return res;
   
...@@ -2478,7 +2478,7 @@ tcptls_write_setup_error: ...@@ -2478,7 +2478,7 @@ tcptls_write_setup_error:
if (packet) { if (packet) {
ao2_t_ref(packet, -1, "could not allocate packet's data"); ao2_t_ref(packet, -1, "could not allocate packet's data");
} }
ast_mutex_unlock(&tcptls_session->lock); ao2_unlock(tcptls_session);
   
return XMIT_ERROR; return XMIT_ERROR;
} }
...@@ -2692,9 +2692,9 @@ static void *_sip_tcp_helper_thread(struct ast_tcptls_session_instance *tcptls_s ...@@ -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)) { if (!fgets(buf, sizeof(buf), tcptls_session->f)) {
ast_mutex_unlock(&tcptls_session->lock); ao2_unlock(tcptls_session);
if (after_poll) { if (after_poll) {
goto cleanup; goto cleanup;
} else { } else {
...@@ -2702,7 +2702,7 @@ static void *_sip_tcp_helper_thread(struct ast_tcptls_session_instance *tcptls_s ...@@ -2702,7 +2702,7 @@ static void *_sip_tcp_helper_thread(struct ast_tcptls_session_instance *tcptls_s
continue; continue;
} }
} }
ast_mutex_unlock(&tcptls_session->lock); ao2_unlock(tcptls_session);
after_poll = 0; after_poll = 0;
if (me->stop) { if (me->stop) {
goto cleanup; goto cleanup;
...@@ -2742,9 +2742,9 @@ static void *_sip_tcp_helper_thread(struct ast_tcptls_session_instance *tcptls_s ...@@ -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))) { 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) { if (after_poll) {
goto cleanup; goto cleanup;
} else { } else {
...@@ -2753,7 +2753,7 @@ static void *_sip_tcp_helper_thread(struct ast_tcptls_session_instance *tcptls_s ...@@ -2753,7 +2753,7 @@ static void *_sip_tcp_helper_thread(struct ast_tcptls_session_instance *tcptls_s
} }
} }
buf[bytes_read] = '\0'; buf[bytes_read] = '\0';
ast_mutex_unlock(&tcptls_session->lock); ao2_unlock(tcptls_session);
after_poll = 0; after_poll = 0;
if (me->stop) { if (me->stop) {
goto cleanup; goto cleanup;
...@@ -2823,10 +2823,10 @@ cleanup: ...@@ -2823,10 +2823,10 @@ cleanup:
} }
   
if (tcptls_session) { if (tcptls_session) {
ast_mutex_lock(&tcptls_session->lock); ao2_lock(tcptls_session);
ast_tcptls_close_session_file(tcptls_session); ast_tcptls_close_session_file(tcptls_session);
tcptls_session->parent = NULL; tcptls_session->parent = NULL;
ast_mutex_unlock(&tcptls_session->lock); ao2_unlock(tcptls_session);
   
ao2_ref(tcptls_session, -1); ao2_ref(tcptls_session, -1);
tcptls_session = NULL; tcptls_session = NULL;
...@@ -155,8 +155,6 @@ struct ast_tcptls_session_instance { ...@@ -155,8 +155,6 @@ struct ast_tcptls_session_instance {
int client; int client;
struct ast_sockaddr remote_address; struct ast_sockaddr remote_address;
struct ast_tcptls_session_args *parent; 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) #if defined(HAVE_FUNOPEN)
......
...@@ -131,12 +131,6 @@ HOOK_T ast_tcptls_server_write(struct ast_tcptls_session_instance *tcptls_sessio ...@@ -131,12 +131,6 @@ HOOK_T ast_tcptls_server_write(struct ast_tcptls_session_instance *tcptls_sessio
return write(tcptls_session->fd, buf, count); 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 /*! \brief
* creates a FILE * from the fd passed by the accept thread. * creates a FILE * from the fd passed by the accept thread.
* This operation is potentially expensive (certificate verification), * This operation is potentially expensive (certificate verification),
...@@ -285,7 +279,7 @@ void *ast_tcptls_server_root(void *data) ...@@ -285,7 +279,7 @@ void *ast_tcptls_server_root(void *data)
} }
continue; continue;
} }
tcptls_session = ao2_alloc(sizeof(*tcptls_session), session_instance_destructor); tcptls_session = ao2_alloc(sizeof(*tcptls_session), NULL);
if (!tcptls_session) { if (!tcptls_session) {
ast_log(LOG_WARNING, "No memory for new session: %s\n", strerror(errno)); ast_log(LOG_WARNING, "No memory for new session: %s\n", strerror(errno));
if (close(fd)) { if (close(fd)) {
...@@ -294,8 +288,6 @@ void *ast_tcptls_server_root(void *data) ...@@ -294,8 +288,6 @@ void *ast_tcptls_server_root(void *data)
continue; continue;
} }
ast_mutex_init(&tcptls_session->lock);
flags = fcntl(fd, F_GETFL); flags = fcntl(fd, F_GETFL);
fcntl(fd, F_SETFL, flags & ~O_NONBLOCK); fcntl(fd, F_SETFL, flags & ~O_NONBLOCK);
tcptls_session->fd = fd; tcptls_session->fd = fd;
...@@ -477,11 +469,10 @@ struct ast_tcptls_session_instance *ast_tcptls_client_create(struct ast_tcptls_s ...@@ -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; goto error;
} }
ast_mutex_init(&tcptls_session->lock);
tcptls_session->client = 1; tcptls_session->client = 1;
tcptls_session->fd = desc->accept_fd; tcptls_session->fd = desc->accept_fd;
tcptls_session->parent = desc; tcptls_session->parent = desc;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment