Skip to content

Commit

Permalink
tls: use atomic ops for config ref counter
Browse files Browse the repository at this point in the history
- closes FS#380
  • Loading branch information
miconda committed Jan 3, 2015
1 parent 395c299 commit af408c8
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions modules/tls/tls_domain.c
Expand Up @@ -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;
}

Expand Down
3 changes: 2 additions & 1 deletion modules/tls/tls_domain.h
Expand Up @@ -30,6 +30,7 @@

#include "../../str.h"
#include "../../ip_addr.h"
#include "../../atomic_ops.h"
#include <openssl/ssl.h>


Expand Down Expand Up @@ -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;


Expand Down
6 changes: 3 additions & 3 deletions modules/tls/tls_server.c
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion modules/tls/tls_util.c
Expand Up @@ -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);
Expand Down

0 comments on commit af408c8

Please sign in to comment.