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
This commit is contained in:
Richard Mudgett 2012-02-28 18:46:34 +00:00
parent 565f411868
commit 85ea4277f1
3 changed files with 13 additions and 24 deletions

View File

@ -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;

View File

@ -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)

View File

@ -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;