Commit 2483a8c7 authored by Mark Andrews's avatar Mark Andrews
Browse files

lock accesses to hash table

parent 4886701c
...@@ -89,6 +89,7 @@ typedef struct filter_instance { ...@@ -89,6 +89,7 @@ typedef struct filter_instance {
* Hash table associating a client object with its persistent data. * Hash table associating a client object with its persistent data.
*/ */
isc_ht_t *ht; isc_ht_t *ht;
isc_mutex_t hlock;
/* /*
* Values configured when the module is loaded. * Values configured when the module is loaded.
...@@ -376,6 +377,7 @@ plugin_register(const char *parameters, ...@@ -376,6 +377,7 @@ plugin_register(const char *parameters,
CHECK(isc_mempool_create(mctx, sizeof(filter_data_t), CHECK(isc_mempool_create(mctx, sizeof(filter_data_t),
&inst->datapool)); &inst->datapool));
CHECK(isc_ht_init(&inst->ht, mctx, 16)); CHECK(isc_ht_init(&inst->ht, mctx, 16));
isc_mutex_init(&inst->hlock);
/* /*
* Fill the mempool with 1K filter_aaaa state objects at * Fill the mempool with 1K filter_aaaa state objects at
...@@ -446,6 +448,7 @@ plugin_destroy(void **instp) { ...@@ -446,6 +448,7 @@ plugin_destroy(void **instp) {
if (inst->ht != NULL) { if (inst->ht != NULL) {
isc_ht_destroy(&inst->ht); isc_ht_destroy(&inst->ht);
isc_mutex_destroy(&inst->hlock);
} }
if (inst->datapool != NULL) { if (inst->datapool != NULL) {
isc_mempool_destroy(&inst->datapool); isc_mempool_destroy(&inst->datapool);
...@@ -519,8 +522,10 @@ client_state_get(const query_ctx_t *qctx, filter_instance_t *inst) { ...@@ -519,8 +522,10 @@ client_state_get(const query_ctx_t *qctx, filter_instance_t *inst) {
filter_data_t *client_state = NULL; filter_data_t *client_state = NULL;
isc_result_t result; isc_result_t result;
LOCK(&inst->hlock);
result = isc_ht_find(inst->ht, (const unsigned char *)&qctx->client, result = isc_ht_find(inst->ht, (const unsigned char *)&qctx->client,
sizeof(qctx->client), (void **)&client_state); sizeof(qctx->client), (void **)&client_state);
UNLOCK(&inst->hlock);
return (result == ISC_R_SUCCESS ? client_state : NULL); return (result == ISC_R_SUCCESS ? client_state : NULL);
} }
...@@ -538,8 +543,10 @@ client_state_create(const query_ctx_t *qctx, filter_instance_t *inst) { ...@@ -538,8 +543,10 @@ client_state_create(const query_ctx_t *qctx, filter_instance_t *inst) {
client_state->mode = NONE; client_state->mode = NONE;
client_state->flags = 0; client_state->flags = 0;
LOCK(&inst->hlock);
result = isc_ht_add(inst->ht, (const unsigned char *)&qctx->client, result = isc_ht_add(inst->ht, (const unsigned char *)&qctx->client,
sizeof(qctx->client), client_state); sizeof(qctx->client), client_state);
UNLOCK(&inst->hlock);
RUNTIME_CHECK(result == ISC_R_SUCCESS); RUNTIME_CHECK(result == ISC_R_SUCCESS);
} }
...@@ -552,8 +559,10 @@ client_state_destroy(const query_ctx_t *qctx, filter_instance_t *inst) { ...@@ -552,8 +559,10 @@ client_state_destroy(const query_ctx_t *qctx, filter_instance_t *inst) {
return; return;
} }
LOCK(&inst->hlock);
result = isc_ht_delete(inst->ht, (const unsigned char *)&qctx->client, result = isc_ht_delete(inst->ht, (const unsigned char *)&qctx->client,
sizeof(qctx->client)); sizeof(qctx->client));
UNLOCK(&inst->hlock);
RUNTIME_CHECK(result == ISC_R_SUCCESS); RUNTIME_CHECK(result == ISC_R_SUCCESS);
isc_mempool_put(inst->datapool, client_state); isc_mempool_put(inst->datapool, client_state);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment