diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-08-27 19:56:52 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2015-08-27 19:56:52 +0200 |
commit | 9c8e3101ceef00342263d57dce3fa61956824985 (patch) | |
tree | 6d6caf88b686200deb1926c9f3ccafeb3b25158a /src/libsystemd-network/sd-pppoe.c | |
parent | 86514214e389f8b1ea3e5aecf9ae2e8d4d782798 (diff) |
network: get rid of more RefCnt usage
A follow-up to 3733eec3e292e4ddb4cba5eb8d3bd8cbee7102d8
Diffstat (limited to 'src/libsystemd-network/sd-pppoe.c')
-rw-r--r-- | src/libsystemd-network/sd-pppoe.c | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/src/libsystemd-network/sd-pppoe.c b/src/libsystemd-network/sd-pppoe.c index ff064f563f..c6c9da812b 100644 --- a/src/libsystemd-network/sd-pppoe.c +++ b/src/libsystemd-network/sd-pppoe.c @@ -36,7 +36,6 @@ #include "random-util.h" #include "socket-util.h" #include "async.h" -#include "refcnt.h" #include "utf8.h" #define PPPOE_MAX_PACKET_SIZE 1484 @@ -68,7 +67,7 @@ typedef struct PPPoETags { } PPPoETags; struct sd_pppoe { - RefCount n_ref; + unsigned n_ref; PPPoEState state; uint64_t host_uniq; @@ -202,23 +201,34 @@ int sd_pppoe_detach_event(sd_pppoe *ppp) { } sd_pppoe *sd_pppoe_ref(sd_pppoe *ppp) { - if (ppp) - assert_se(REFCNT_INC(ppp->n_ref) >= 2); + + if (!ppp) + return NULL; + + assert(ppp->n_ref > 0); + ppp->n_ref++; return ppp; } sd_pppoe *sd_pppoe_unref(sd_pppoe *ppp) { - if (ppp && REFCNT_DEC(ppp->n_ref) <= 0) { - pppoe_tags_clear(&ppp->tags); - free(ppp->ifname); - free(ppp->service_name); - sd_pppoe_stop(ppp); - sd_pppoe_detach_event(ppp); - - free(ppp); - } + if (!ppp) + return NULL; + + assert(ppp->n_ref > 0); + ppp->n_ref--; + + if (ppp->n_ref > 0) + return NULL; + + pppoe_tags_clear(&ppp->tags); + free(ppp->ifname); + free(ppp->service_name); + sd_pppoe_stop(ppp); + sd_pppoe_detach_event(ppp); + + free(ppp); return NULL; } @@ -231,7 +241,7 @@ int sd_pppoe_new (sd_pppoe **ret) { if (!ppp) return -ENOMEM; - ppp->n_ref = REFCNT_INIT; + ppp->n_ref = 1; ppp->state = _PPPOE_STATE_INVALID; ppp->ifindex = -1; ppp->fd = -1; |