From: Alan T. DeKok Date: Tue, 29 Nov 2011 09:04:32 +0000 (+0100) Subject: Fixed mutex issues X-Git-Tag: release_3_0_0_beta0~462 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=79a3a876d55320edc69c6fb42ff5d10730a5151e;p=thirdparty%2Ffreeradius-server.git Fixed mutex issues --- diff --git a/src/main/connection.c b/src/main/connection.c index 63cb3031c20..d28343fc2e1 100644 --- a/src/main/connection.c +++ b/src/main/connection.c @@ -294,6 +294,8 @@ static fr_connection_t *fr_connection_find(fr_connection_pool_t *fc, void *conn) { fr_connection_t *this; + if (!fc || !conn) return NULL; + pthread_mutex_lock(&fc->mutex); /* @@ -313,12 +315,8 @@ int fr_connection_del(fr_connection_pool_t *fc, void *conn) { fr_connection_t *this; - if (!fc || !conn) return 0; - this = fr_connection_find(fc, conn); - if (!this) { - return 0; - } + if (!this) return 0; if (this->used) { pthread_mutex_unlock(&fc->mutex); @@ -501,15 +499,19 @@ static int fr_connection_manage(fr_connection_pool_t *fc, } +/* + * Called with the mutex held. Releases it. + */ static int fr_connection_pool_check(fr_connection_pool_t *fc) { int spare, spawn; time_t now = time(NULL); fr_connection_t *this, *next; - if (fc->last_checked == now) return 1; - - pthread_mutex_lock(&fc->mutex); + if (fc->last_checked == now) { + pthread_mutex_unlock(&fc->mutex); + return 1; + } spare = fc->num - fc->active; @@ -524,6 +526,7 @@ static int fr_connection_pool_check(fr_connection_pool_t *fc) if (spawn) { pthread_mutex_unlock(&fc->mutex); fr_connection_spawn(fc, now); /* ignore return code */ + pthread_mutex_lock(&fc->mutex); } } @@ -575,11 +578,11 @@ int fr_connection_check(fr_connection_pool_t *fc, void *conn) if (!fc) return 1; - if (!conn) return fr_connection_pool_check(fc); - now = time(NULL); pthread_mutex_lock(&fc->mutex); + if (!conn) return fr_connection_pool_check(fc); + for (this = fc->head; this != NULL; this = this->next) { if (this->connection == conn) { fr_connection_manage(fc, conn, now); @@ -647,12 +650,8 @@ void fr_connection_release(fr_connection_pool_t *fc, void *conn) { fr_connection_t *this; - if (!fc || !conn) return; - this = fr_connection_find(fc, conn); - if (!this) { - return; - } + if (!this) return; rad_assert(this->used == TRUE); this->used = FALSE;