tree-wide: use DEFINE_TRIVIAL_REF_UNREF_FUNC() macro or friends where applicable

This commit is contained in:
Yu Watanabe
2018-08-27 14:01:46 +09:00
parent a6a08596ef
commit 8301aa0bf1
34 changed files with 179 additions and 766 deletions
+4 -19
View File
@@ -29,25 +29,8 @@ int bpf_program_new(uint32_t prog_type, BPFProgram **ret) {
return 0;
}
BPFProgram *bpf_program_ref(BPFProgram *p) {
if (!p)
return NULL;
assert(p->n_ref > 0);
p->n_ref++;
return p;
}
BPFProgram *bpf_program_unref(BPFProgram *p) {
if (!p)
return NULL;
assert(p->n_ref > 0);
p->n_ref--;
if (p->n_ref > 0)
return NULL;
static BPFProgram *bpf_program_free(BPFProgram *p) {
assert(p);
/* Unfortunately, the kernel currently doesn't implicitly detach BPF programs from their cgroups when the last
* fd to the BPF program is closed. This has nasty side-effects since this means that abnormally terminated
@@ -66,6 +49,8 @@ BPFProgram *bpf_program_unref(BPFProgram *p) {
return mfree(p);
}
DEFINE_TRIVIAL_REF_UNREF_FUNC(BPFProgram, bpf_program, bpf_program_free);
int bpf_program_add_instructions(BPFProgram *p, const struct bpf_insn *instructions, size_t count) {
assert(p);
+3 -19
View File
@@ -171,32 +171,16 @@ Table *table_new_internal(const char *first_header, ...) {
return TAKE_PTR(t);
}
static TableData *table_data_unref(TableData *d) {
if (!d)
return NULL;
assert(d->n_ref > 0);
d->n_ref--;
if (d->n_ref > 0)
return NULL;
static TableData *table_data_free(TableData *d) {
assert(d);
free(d->formatted);
return mfree(d);
}
DEFINE_PRIVATE_TRIVIAL_REF_UNREF_FUNC(TableData, table_data, table_data_free);
DEFINE_TRIVIAL_CLEANUP_FUNC(TableData*, table_data_unref);
static TableData *table_data_ref(TableData *d) {
if (!d)
return NULL;
assert(d->n_ref > 0);
d->n_ref++;
return d;
}
Table *table_unref(Table *t) {
size_t i;