bus: make conn_seq_last atomic64_t
authorDaniel Mack <zonque@gmail.com>
Thu, 16 Jan 2014 18:35:53 +0000 (19:35 +0100)
committerDaniel Mack <zonque@gmail.com>
Thu, 16 Jan 2014 18:35:55 +0000 (19:35 +0100)
conn->id is now assigned outside of the bus' lock, so an atomic64_t is
nicer.

bus.c
bus.h
connection.c

diff --git a/bus.c b/bus.c
index bd196cae1c0f8a077f2867bacedc7b258893b4ed..90711b5f673db4d906932fc305326295f25bf4f7 100644 (file)
--- 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 87395c7acbe082acf7bfdeba4c7b60c13792f8f8..15c0af4648fae110b1bacfb1bd64c7ca9574f778 100644 (file)
--- 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;
index 93ffc941dce0a4a12ad1ab08ed0786c718210f27..c9f6f009b0ccc56cb41d09826f1cd84e1d95f3bf 100644 (file)
@@ -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;