atomic message unref issues on ARM

Jim Harvy jimharvy at gmail.com
Fri Jul 17 00:03:21 PDT 2009


hey all,

i've encountered a problem when using Dbus in an ARM environment (actually
in Android).
i have the following stack trace:

#0  __dl__start () at bionic/linker/arch/arm/begin.S:35
#1  0xae832a46 in _dbus_abort () at external/dbus/dbus/dbus-sysdeps.c:84
#2  0xae817e3e in _dbus_real_assert (condition=<value optimized out>,
condition_text=0xae83f318 "message->refcount.value == 0",
    file=0xae83eff8 "external/dbus/dbus/dbus-message.c", line=576,
func=0xae8407bc "dbus_message_cache_or_finalize")
    at external/dbus/dbus/dbus-internals.c:813
#3  0xae82236a in dbus_message_cache_or_finalize (message=0x18f420) at
external/dbus/dbus/dbus-message.c:576
#4  0xae82246a in dbus_message_unref (message=0x18f420) at
external/dbus/dbus/dbus-message.c:1402

when debugging closer we have

(gdb) f 3
#3  0xae82236a in dbus_message_cache_or_finalize (message=0x18f420) at
external/dbus/dbus/dbus- message.c:576
576      _dbus_assert (message->refcount.value == 0);
(gdb) p message->refcount
$30 = {value = 1}

and in the unref we get:

(gdb) f 4
#4  0xae82246a in dbus_message_unref (message=0x18f420) at
external/dbus/dbus/dbus-message.c:1402
1402          dbus_message_cache_or_finalize (message);
(gdb) l -5
1387    dbus_message_unref (DBusMessage *message)
1388    {
1389     dbus_int32_t old_refcount;
1390
1391      _dbus_return_if_fail (message != NULL);
1392      _dbus_return_if_fail (message->generation ==
_dbus_current_generation);
1393      _dbus_return_if_fail (!message->in_cache);
1394
1395      old_refcount = _dbus_atomic_dec (&message->refcount);
1396
(gdb) l
1397      _dbus_assert (old_refcount >= 0);
1398
1399      if (old_refcount == 1)
1400        {
1401          /* Calls application callbacks! */
1402          dbus_message_cache_or_finalize (message);
1403        }
1404    }
1405
1406    /**
(gdb) p old_refcount
$32 = 1


seems like the dbus_atomic_dec function is not really "atomic" (in the sense
the value is not immediately updated).
note that in my version of dbus (based on 1.0.3 i believe) the
"_dbus_atomic_dec" function does not use "atomic_exchange_and_add".
the function is defined as follows:

dbus_int32_t
_dbus_atomic_dec (DBusAtomic *atomic)
{
#ifdef DBUS_USE_ATOMIC_INT_486
  return atomic_exchange_and_add (atomic, -1);
#else
  dbus_int32_t res;

  _DBUS_LOCK (atomic);
  res = atomic->value;
  atomic->value -= 1;
  _DBUS_UNLOCK (atomic);
  return res;
#endif
}


and in the android dbus version we have the macro definition:

#undef DBUS_USE_ATOMIC_INT_486

#if (defined(__i386__) || defined(__x86_64__))
#define DBUS_USE_ATOMIC_INT_486 1
#endif

i noticed this was changed in 1.2.4 to be a constant 1 (and thus use the
"atomic_exchange_and_add" function).
should this solve my problem?

BR,
Jim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freedesktop.org/archives/dbus/attachments/20090717/e32a5217/attachment.htm 


More information about the dbus mailing list