From b5adfeaa382d042432c055afb3e0168dae646f7d Mon Sep 17 00:00:00 2001 From: Daniel Mack Date: Thu, 16 Jan 2014 19:35:53 +0100 Subject: [PATCH] bus: make conn_seq_last atomic64_t conn->id is now assigned outside of the bus' lock, so an atomic64_t is nicer. --- bus.c | 1 + bus.h | 2 +- connection.c | 4 +--- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/bus.c b/bus.c index bd196ca..90711b5 100644 --- a/bus.c +++ b/bus.c @@ -209,6 +209,7 @@ int kdbus_bus_new(struct kdbus_ns *ns, hash_init(b->conn_hash); INIT_LIST_HEAD(&b->ep_list); INIT_LIST_HEAD(&b->monitors_list); + atomic64_set(&b->conn_seq_last, 0); /* generate unique ID for this bus */ get_random_bytes(b->id128, sizeof(b->id128)); diff --git a/bus.h b/bus.h index 87395c7..15c0af4 100644 --- a/bus.h +++ b/bus.h @@ -54,7 +54,7 @@ struct kdbus_bus { u64 id; struct mutex lock; u64 ep_seq_last; - u64 conn_seq_last; + atomic64_t conn_seq_last; struct idr conn_idr; DECLARE_HASHTABLE(conn_hash, 6); struct list_head ep_list; diff --git a/connection.c b/connection.c index 93ffc94..c9f6f00 100644 --- a/connection.c +++ b/connection.c @@ -1600,9 +1600,7 @@ int kdbus_conn_new(struct kdbus_ep *ep, conn->ep = kdbus_ep_ref(ep); /* get new id for this connection */ - mutex_lock(&bus->lock); - conn->id = ++bus->conn_seq_last; - mutex_unlock(&bus->lock); + conn->id = atomic64_inc_return(&bus->conn_seq_last); /* return properties of this connection to the caller */ hello->bus_flags = bus->bus_flags; -- 2.34.1