Module: kamailio
Branch: master
Commit: af408c882ed70028c7dbc84b7876be996a49235e
URL:
https://github.com/kamailio/kamailio/commit/af408c882ed70028c7dbc84b7876be9…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2015-01-03T23:29:40+01:00
tls: use atomic ops for config ref counter
- closes FS#380
---
Modified: modules/tls/tls_domain.c
Modified: modules/tls/tls_domain.h
Modified: modules/tls/tls_server.c
Modified: modules/tls/tls_util.c
---
Diff:
https://github.com/kamailio/kamailio/commit/af408c882ed70028c7dbc84b7876be9…
Patch:
https://github.com/kamailio/kamailio/commit/af408c882ed70028c7dbc84b7876be9…
---
diff --git a/modules/tls/tls_domain.c b/modules/tls/tls_domain.c
index 3fed7b2..395fd4e 100644
--- a/modules/tls/tls_domain.c
+++ b/modules/tls/tls_domain.c
@@ -1181,6 +1181,7 @@ tls_domains_cfg_t* tls_new_cfg(void)
return 0;
}
memset(r, 0, sizeof(tls_domains_cfg_t));
+ atomic_set(&r->ref_count, 0);
return r;
}
diff --git a/modules/tls/tls_domain.h b/modules/tls/tls_domain.h
index 1eea6db..dce7850 100644
--- a/modules/tls/tls_domain.h
+++ b/modules/tls/tls_domain.h
@@ -30,6 +30,7 @@
#include "../../str.h"
#include "../../ip_addr.h"
+#include "../../atomic_ops.h"
#include <openssl/ssl.h>
@@ -117,7 +118,7 @@ typedef struct tls_domains_cfg {
tls_domain_t* srv_list; /**< Server domain list */
tls_domain_t* cli_list; /**< Client domain list */
struct tls_domains_cfg* next; /**< Next element in the garbage list */
- volatile int ref_count; /**< How many connections use this configuration
*/
+ atomic_t ref_count; /**< How many connections use this configuration */
} tls_domains_cfg_t;
diff --git a/modules/tls/tls_server.c b/modules/tls/tls_server.c
index 26de1f3..4c281e3 100644
--- a/modules/tls/tls_server.c
+++ b/modules/tls/tls_server.c
@@ -165,7 +165,7 @@ static int tls_complete_init(struct tcp_connection* c)
* is to ensure that, while on the garbage queue, the configuration does
* not get deleted if there are still connection referencing its SSL_CTX
*/
- cfg->ref_count++;
+ atomic_inc(&cfg->ref_count);
lock_release(tls_domains_cfg_lock);
if (c->flags & F_CONN_PASSIVE) {
@@ -218,7 +218,7 @@ static int tls_complete_init(struct tcp_connection* c)
return 0;
error:
- cfg->ref_count--;
+ atomic_dec(&cfg->ref_count);
if (data) shm_free(data);
error2:
return -1;
@@ -574,7 +574,7 @@ void tls_h_tcpconn_clean(struct tcp_connection *c)
if (c->extra_data) {
extra = (struct tls_extra_data*)c->extra_data;
SSL_free(extra->ssl);
- extra->cfg->ref_count--;
+ atomic_dec(&extra->cfg->ref_count);
if (extra->ct_wq)
tls_ct_wq_free(&extra->ct_wq);
if (extra->enc_rd_buf) {
diff --git a/modules/tls/tls_util.c b/modules/tls/tls_util.c
index 88416a1..4889eb3 100644
--- a/modules/tls/tls_util.c
+++ b/modules/tls/tls_util.c
@@ -83,7 +83,7 @@ void collect_garbage(void)
while(cur) {
next = cur->next;
- if (cur->ref_count == 0) {
+ if (atomic_get(&cur->ref_count) == 0) {
/* Not referenced by any existing connection */
prev->next = cur->next;
tls_free_cfg(cur);