thread-safety of counters

Adrian Szyndela adrian.s at samsung.com
Thu Mar 26 08:24:52 PDT 2015


W dniu 25.02.2015 o 09:54, Adrian Szyndela pisze:
> I just need a few answers, and I'll prepare a patch:
> an existing mutex or a new one? If an existing, then which one? If a new
> one, then to what objects should it be added? Counters? Messages?

I'll try to answer myself.

We can't use existing mutexes from DBusConnection, because there might
be already no connection object while freeing a message.

Using one of global locks seems to make no sense for local objects.

I found only one more mutex, in DBusServer, but that is not relevant.

So, to use a mutex, we need to introduce a new one. As it is needed only
for DBusCounter objects locally, it seems natural to introduce such
mutex in there.

I attach a patch that does exactly this.

> some rationale for "mutex vs. atomic"?

For future reference: an example. In _dbus_counter_notify()
notify_function is called depending on notify_pending field value. On
the other hand _dbus_counter_set_notify() can be called from
_dbus_transport_finalize_base() at the same time, interfering with
_dbus_counter_notify(). This one would be hard to fix with atomics.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mutex-counters.patch
Type: text/x-patch
Size: 3892 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/dbus/attachments/20150326/7f88ec65/attachment.bin>


More information about the dbus mailing list