diff options
author | Philip Withnall <withnall@endlessm.com> | 2017-02-03 10:03:56 +0000 |
---|---|---|
committer | Philip Withnall <withnall@endlessm.com> | 2017-02-05 14:59:44 +0100 |
commit | c131865f57c2786d1a498d58b9b4c1333397798c (patch) | |
tree | 64c885b3a8ef49320899541359ac25c07b35f265 | |
parent | b1f14143e5e10ac0d540879ff3e1f5984429c411 (diff) | |
download | glib-c131865f57c2786d1a498d58b9b4c1333397798c.tar.gz |
gdbus: Fix atomic accesses to global name watch ID
https://bugzilla.gnome.org/show_bug.cgi?id=777307
-rw-r--r-- | gio/gdbusnamewatching.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/gio/gdbusnamewatching.c b/gio/gdbusnamewatching.c index 01ab4ce24..14603c5e4 100644 --- a/gio/gdbusnamewatching.c +++ b/gio/gdbusnamewatching.c @@ -77,7 +77,10 @@ typedef struct gboolean initialized; } Client; -static guint next_global_id = 1; +/* Must be accessed atomically. */ +static volatile guint next_global_id = 1; + +/* Must be accessed with @lock held. */ static GHashTable *map_id_to_client = NULL; static Client * @@ -562,7 +565,7 @@ g_bus_watch_name (GBusType bus_type, client = g_new0 (Client, 1); client->ref_count = 1; - client->id = next_global_id++; /* TODO: uh oh, handle overflow */ + client->id = g_atomic_int_add (&next_global_id, 1); /* TODO: uh oh, handle overflow */ client->name = g_strdup (name); client->flags = flags; client->name_appeared_handler = name_appeared_handler; @@ -624,7 +627,7 @@ guint g_bus_watch_name_on_connection (GDBusConnection *connection, client = g_new0 (Client, 1); client->ref_count = 1; - client->id = next_global_id++; /* TODO: uh oh, handle overflow */ + client->id = g_atomic_int_add (&next_global_id, 1); /* TODO: uh oh, handle overflow */ client->name = g_strdup (name); client->flags = flags; client->name_appeared_handler = name_appeared_handler; |