Commit 48a70a9a authored by Daniel Salzman's avatar Daniel Salzman

knot: simplify rcu_call wrapper

parent 40e6c1f8
......@@ -206,6 +206,7 @@ static int axfr_init(struct refresh_data *data)
static void axfr_cleanup(struct refresh_data *data)
{
zone_contents_deep_free(data->axfr.zone);
data->axfr.zone = NULL;
}
static int axfr_finalize(struct refresh_data *data)
......
......@@ -464,18 +464,17 @@ void update_rollback(apply_ctx_t *ctx)
init_list(&ctx->old_data);
}
void update_free_zone(zone_contents_t **contents)
void update_free_zone(zone_contents_t *contents)
{
if (contents == NULL || *contents == NULL) {
if (contents == NULL) {
return;
}
(void)zone_tree_apply((*contents)->nodes, free_additional, NULL);
zone_tree_deep_free(&(*contents)->nodes);
zone_tree_deep_free(&(*contents)->nsec3_nodes);
(void)zone_tree_apply(contents->nodes, free_additional, NULL);
zone_tree_deep_free(&contents->nodes);
zone_tree_deep_free(&contents->nsec3_nodes);
dnssec_nsec3_params_free(&(*contents)->nsec3_params);
dnssec_nsec3_params_free(&contents->nsec3_params);
free(*contents);
*contents = NULL;
free(contents);
}
......@@ -147,4 +147,4 @@ void update_rollback(apply_ctx_t *ctx);
*
* \param contents Contents to free.
*/
void update_free_zone(zone_contents_t **contents);
void update_free_zone(zone_contents_t *contents);
......@@ -575,7 +575,7 @@ void changeset_from_contents_free(changeset_t *ch)
assert(ch->soa_from == NULL);
assert(zone_contents_is_empty(ch->remove));
update_free_zone(&ch->add);
update_free_zone(ch->add);
zone_contents_deep_free(ch->remove);
knot_rrset_free(ch->soa_from, NULL);
......
......@@ -285,7 +285,7 @@ void zone_update_clear(zone_update_t *update)
zone_contents_deep_free(update->new_cont);
} else {
update_rollback(update->a_ctx);
update_free_zone(&update->new_cont);
update_free_zone(update->new_cont);
}
changeset_clear(&update->change);
} else if (update->flags & UPDATE_FULL) {
......@@ -639,18 +639,14 @@ typedef struct {
struct rcu_head rcuhead;
void (*callback)(void *);
void *ctx;
bool call_ctx_addr;
bool free_ctx;
} callrcu_wrapper_t;
static void callrcu_wrapper_cb(struct rcu_head *param)
{
callrcu_wrapper_t *wrap = (callrcu_wrapper_t *)param;
if (wrap->call_ctx_addr) {
// Paradigm free_fun(type_t **t) freeing the pointer completely.
wrap->callback(&wrap->ctx);
} else {
// Paradigm clear_fun(type_t *t) just clearing the contents of type_t.
wrap->callback(wrap->ctx);
if (wrap->free_ctx) {
free(wrap->ctx);
}
free(wrap);
......@@ -660,13 +656,13 @@ static void callrcu_wrapper_cb(struct rcu_head *param)
}
/* NOTE: Does nothing if not enough memory. */
static void callrcu_wrapper(void *ctx, void (*callback)(void *), bool call_ctx_addr)
static void callrcu_wrapper(void *ctx, void *callback, bool free_ctx)
{
callrcu_wrapper_t *wrap = calloc(1, sizeof(callrcu_wrapper_t));
if (wrap != NULL) {
wrap->callback = callback;
wrap->ctx = ctx;
wrap->call_ctx_addr = call_ctx_addr;
wrap->free_ctx = free_ctx;
call_rcu((struct rcu_head *)wrap, callrcu_wrapper_cb);
}
}
......@@ -709,16 +705,16 @@ int zone_update_commit(conf_t *conf, zone_update_t *update)
/* Sync RCU. */
if (update->flags & UPDATE_FULL) {
assert(update->new_cont_deep_copy);
callrcu_wrapper(old_contents, (void (*)(void *))zone_contents_deep_free, true);
callrcu_wrapper(old_contents, zone_contents_deep_free, false);
} else if (update->flags & UPDATE_INCREMENTAL) {
if (update->new_cont_deep_copy) {
callrcu_wrapper(old_contents, (void (*)(void *))zone_contents_deep_free, true);
callrcu_wrapper(old_contents, zone_contents_deep_free, false);
} else {
callrcu_wrapper(old_contents, (void (*)(void *))update_free_zone, true);
callrcu_wrapper(old_contents, update_free_zone, false);
}
changeset_clear(&update->change);
}
callrcu_wrapper(update->a_ctx, (void (*)(void *))update_cleanup, false);
callrcu_wrapper(update->a_ctx, update_cleanup, true);
update->a_ctx = NULL;
update->new_cont = NULL;
......
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