From 4c97df787d5e207fe83e41feddee5d59345854b1 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Thu, 12 Mar 2015 21:13:47 +1100 Subject: [PATCH] Remove use of upgradeable locks in connector --- src/connector.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/connector.c b/src/connector.c index f6d9f1ab..92665bed 100644 --- a/src/connector.c +++ b/src/connector.c @@ -214,12 +214,11 @@ static int drop_client(cdata_t *cdata, client_instance_t *client) int64_t client_id = 0; int fd; - ck_ilock(&cdata->lock); + ck_wlock(&cdata->lock); fd = client->fd; if (fd != -1) { client_id = client->id; - ck_ulock(&cdata->lock); Close(client->fd); HASH_DEL(cdata->clients, client); DL_APPEND(cdata->dead_clients, client); @@ -227,9 +226,8 @@ static int drop_client(cdata_t *cdata, client_instance_t *client) * epoll list. */ __dec_instance_ref(client); cdata->dead_generated++; - ck_dwilock(&cdata->lock); } - ck_uilock(&cdata->lock); + ck_wunlock(&cdata->lock); if (fd > -1) LOGINFO("Connector dropped client %"PRId64" fd %d", client_id, fd); @@ -575,17 +573,15 @@ static void send_client(cdata_t *cdata, int64_t id, char *buf) return; } - ck_ilock(&cdata->lock); + ck_wlock(&cdata->lock); HASH_FIND_I64(cdata->clients, &id, client); if (likely(client)) { fd = client->fd; /* Grab a reference to this client until the sender_send has * completed processing. */ - ck_ulock(&cdata->lock); __inc_instance_ref(client); - ck_dwilock(&cdata->lock); } - ck_uilock(&cdata->lock); + ck_wunlock(&cdata->lock); if (unlikely(fd == -1)) { ckpool_t *ckp = cdata->ckp; @@ -617,14 +613,11 @@ static client_instance_t *ref_client_by_id(cdata_t *cdata, int64_t id) { client_instance_t *client; - ck_ilock(&cdata->lock); + ck_wlock(&cdata->lock); HASH_FIND_I64(cdata->clients, &id, client); - if (client) { - ck_ulock(&cdata->lock); + if (client) __inc_instance_ref(client); - ck_dwilock(&cdata->lock); - } - ck_uilock(&cdata->lock); + ck_wunlock(&cdata->lock); return client; }