浏览代码

tls: use atomic ops for config ref counter

- closes FS#380
Daniel-Constantin Mierla 10 年之前
父节点
当前提交
af408c882e
共有 4 个文件被更改,包括 7 次插入5 次删除
  1. 1 0
      modules/tls/tls_domain.c
  2. 2 1
      modules/tls/tls_domain.h
  3. 3 3
      modules/tls/tls_server.c
  4. 1 1
      modules/tls/tls_util.c

+ 1 - 0
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;
 }
 

+ 2 - 1
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;
 
 

+ 3 - 3
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) {

+ 1 - 1
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);