summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-03-01 18:31:45 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-03-04 14:16:39 +0100
commitf23ab4dc3ca9a97470ca46775a6cd406a82de6d5 (patch)
treec8cc1b41632a9f9d49528c29ab383df0c22d738a /src
parentaf407110505d7394b7e2b45566affa1fd0fed00b (diff)
downloadsystemd-f23ab4dc3ca9a97470ca46775a6cd406a82de6d5.tar.gz
systemd-f23ab4dc3ca9a97470ca46775a6cd406a82de6d5.tar.bz2
systemd-f23ab4dc3ca9a97470ca46775a6cd406a82de6d5.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/libsystemd/sd-netlink/netlink-internal.h5
-rw-r--r--src/libsystemd/sd-netlink/netlink-message.c11
-rw-r--r--src/libsystemd/sd-netlink/netlink-socket.c1
-rw-r--r--src/libsystemd/sd-netlink/rtnl-message.c1
-rw-r--r--src/libsystemd/sd-netlink/sd-netlink.c4
5 files changed, 8 insertions, 14 deletions
diff --git a/src/libsystemd/sd-netlink/netlink-internal.h b/src/libsystemd/sd-netlink/netlink-internal.h
index 98de4f0a83..a8af3fc63b 100644
--- a/src/libsystemd/sd-netlink/netlink-internal.h
+++ b/src/libsystemd/sd-netlink/netlink-internal.h
@@ -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;
diff --git a/src/libsystemd/sd-netlink/netlink-message.c b/src/libsystemd/sd-netlink/netlink-message.c
index f878fc9471..bf3ac95400 100644
--- a/src/libsystemd/sd-netlink/netlink-message.c
+++ b/src/libsystemd/sd-netlink/netlink-message.c
@@ -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);
}
diff --git a/src/libsystemd/sd-netlink/netlink-socket.c b/src/libsystemd/sd-netlink/netlink-socket.c
index 432e8e8c06..d1c95b260f 100644
--- a/src/libsystemd/sd-netlink/netlink-socket.c
+++ b/src/libsystemd/sd-netlink/netlink-socket.c
@@ -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"
diff --git a/src/libsystemd/sd-netlink/rtnl-message.c b/src/libsystemd/sd-netlink/rtnl-message.c
index 2d4d00e0eb..ccc497de09 100644
--- a/src/libsystemd/sd-netlink/rtnl-message.c
+++ b/src/libsystemd/sd-netlink/rtnl-message.c
@@ -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"
diff --git a/src/libsystemd/sd-netlink/sd-netlink.c b/src/libsystemd/sd-netlink/sd-netlink.c
index d83952d0cc..f3e267f007 100644
--- a/src/libsystemd/sd-netlink/sd-netlink.c
+++ b/src/libsystemd/sd-netlink/sd-netlink.c
@@ -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);