[patch] Add a level of abstraction to condvars and mutexes so we can initalize them late

Havoc Pennington hp at redhat.com
Wed Aug 16 11:17:59 PDT 2006


Hi,

Looks good, a few minor things inline -

John (J5) Palmieri wrote:
>> -  DBusMutex *mutex; /**< Lock on the entire DBusConnection */
>> +  DBusMutex *mutex; /**< Location of lock on the entire DBusConnection */

Comment change no longer accurate

>>    return _dbus_data_slot_allocator_alloc (&slot_allocator,
>> -                                          _DBUS_LOCK_NAME (message_slots),
>> +                                          (DBusMutex **)&_DBUS_LOCK_NAME (message_slots),
>>                                            slot_p);

What is the warning without this cast?

>>    const DBusServerVTable *vtable;             /**< Virtual methods for this instance. */
>> -  DBusMutex *mutex;                           /**< Lock on the server object */
>> +  DBusMutex *mutex;                           /**< Location of lock on the server object */
>>  

Comment change left over

>> +void
>> +_dbus_mutex_new_at_location (DBusMutex **location_p)
>> +{
>> +  _dbus_assert (location_p != NULL);
>> +
>> +  *location_p = _dbus_mutex_new();
>> +
>> +  if (thread_init_generation == 0 && *location_p)
>> +    {
>> +      if (!_dbus_list_append (&uninitialized_mutex_list, location_p))
>> +        {
>> +	  _dbus_mutex_free (*location_p);
>> +	  *location_p = NULL;
>> +	}
>> +    }
>> +}

This will need to return bool for whether it ran out of memory.

The test thread_init_generation == 0 should be
thread_init_generation != _dbus_current_generation instead, so multiple 
generations can be used.

>> +void 
>> +_dbus_condvar_new_at_location (DBusCondVar **location_p)
>> +{
>> +  *location_p = _dbus_condvar_new();
>> +
>> +  if (thread_init_generation == 0 && *location_p)
>> +    {
>> +      if (!_dbus_list_append (&uninitialized_condvar_list, location_p))
>> +        {
>> +          _dbus_condvar_free (*location_p);
>> +          *location_p = NULL;
>> +        }
>> +    }
>> +}

Same two comments about returning bool and the generation check

>> +  if (!init_uninitialized_locks ())
>> +    return FALSE;
>> +

If this fails, the whole thread init should fail atomically - that is, 
set the thread funcs and thread init generation and so forth back to 
what they were.

Havoc



More information about the dbus mailing list