sd-netlink: do not use atomic reference counters
Same as with the other users, any non-trivial use of the objects requires use from a single thread only or external locking. Using atomic operations just for reference counts is not useful.
This commit is contained in:
parent
af40711050
commit
f23ab4dc3c
|
@ -8,7 +8,6 @@
|
|||
#include "list.h"
|
||||
#include "netlink-types.h"
|
||||
#include "prioq.h"
|
||||
#include "refcnt.h"
|
||||
|
||||
#define RTNL_DEFAULT_TIMEOUT ((usec_t) (25 * USEC_PER_SEC))
|
||||
|
||||
|
@ -56,7 +55,7 @@ struct sd_netlink_slot {
|
|||
};
|
||||
|
||||
struct sd_netlink {
|
||||
RefCount n_ref;
|
||||
unsigned n_ref;
|
||||
|
||||
int fd;
|
||||
|
||||
|
@ -114,7 +113,7 @@ struct netlink_container {
|
|||
};
|
||||
|
||||
struct sd_netlink_message {
|
||||
RefCount n_ref;
|
||||
unsigned n_ref;
|
||||
|
||||
sd_netlink *rtnl;
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
#include "netlink-internal.h"
|
||||
#include "netlink-types.h"
|
||||
#include "netlink-util.h"
|
||||
#include "refcnt.h"
|
||||
#include "socket-util.h"
|
||||
#include "util.h"
|
||||
|
||||
|
@ -36,7 +35,7 @@ int message_new_empty(sd_netlink *rtnl, sd_netlink_message **ret) {
|
|||
if (!m)
|
||||
return -ENOMEM;
|
||||
|
||||
m->n_ref = REFCNT_INIT;
|
||||
m->n_ref = 1;
|
||||
m->protocol = rtnl->protocol;
|
||||
m->sealed = false;
|
||||
|
||||
|
@ -96,12 +95,10 @@ int sd_netlink_message_request_dump(sd_netlink_message *m, int dump) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
DEFINE_ATOMIC_REF_FUNC(sd_netlink_message, sd_netlink_message);
|
||||
DEFINE_TRIVIAL_REF_FUNC(sd_netlink_message, sd_netlink_message);
|
||||
|
||||
sd_netlink_message *sd_netlink_message_unref(sd_netlink_message *m) {
|
||||
sd_netlink_message *t;
|
||||
|
||||
while (m && REFCNT_DEC(m->n_ref) == 0) {
|
||||
while (m && --m->n_ref == 0) {
|
||||
unsigned i;
|
||||
|
||||
free(m->hdr);
|
||||
|
@ -109,7 +106,7 @@ sd_netlink_message *sd_netlink_message_unref(sd_netlink_message *m) {
|
|||
for (i = 0; i <= m->n_containers; i++)
|
||||
free(m->containers[i].attributes);
|
||||
|
||||
t = m;
|
||||
sd_netlink_message *t = m;
|
||||
m = m->next;
|
||||
free(t);
|
||||
}
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
#include "netlink-internal.h"
|
||||
#include "netlink-types.h"
|
||||
#include "netlink-util.h"
|
||||
#include "refcnt.h"
|
||||
#include "socket-util.h"
|
||||
#include "util.h"
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
#include "netlink-internal.h"
|
||||
#include "netlink-types.h"
|
||||
#include "netlink-util.h"
|
||||
#include "refcnt.h"
|
||||
#include "socket-util.h"
|
||||
#include "util.h"
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ static int sd_netlink_new(sd_netlink **ret) {
|
|||
return -ENOMEM;
|
||||
|
||||
*rtnl = (sd_netlink) {
|
||||
.n_ref = REFCNT_INIT,
|
||||
.n_ref = 1,
|
||||
.fd = -1,
|
||||
.sockaddr.nl.nl_family = AF_NETLINK,
|
||||
.original_pid = getpid_cached(),
|
||||
|
@ -182,7 +182,7 @@ static sd_netlink *netlink_free(sd_netlink *rtnl) {
|
|||
return mfree(rtnl);
|
||||
}
|
||||
|
||||
DEFINE_ATOMIC_REF_UNREF_FUNC(sd_netlink, sd_netlink, netlink_free);
|
||||
DEFINE_TRIVIAL_REF_UNREF_FUNC(sd_netlink, sd_netlink, netlink_free);
|
||||
|
||||
static void rtnl_seal_message(sd_netlink *rtnl, sd_netlink_message *m) {
|
||||
assert(rtnl);
|
||||
|
|
Loading…
Reference in New Issue