25 #include "dbus-dataslot.h"    26 #include "dbus-threads-internal.h"    52   allocator->
lock = lock;
    70                                  dbus_int32_t          *slot_id_p)
    74   if (!_dbus_lock (allocator->
lock))
    94       while (slot < allocator->n_allocated_slots)
   134   _dbus_verbose (
"Allocated slot %d on allocator %p total %d slots allocated %d used\n",
   138   _dbus_unlock (allocator->
lock);
   155                                 dbus_int32_t          *slot_id_p)
   157   if (!_dbus_lock (allocator->
lock))
   159         "before we allocated this slot");
   161   _dbus_assert (*slot_id_p < allocator->n_allocated_slots);
   169       _dbus_unlock (allocator->
lock);
   174   _dbus_verbose (
"Freeing slot %d on allocator %p total %d allocated %d used\n",
   189   _dbus_unlock (allocator->
lock);
   229 #ifndef DBUS_DISABLE_ASSERT   234   if (!_dbus_lock (allocator->
lock))
   236         "before we allocated this slot");
   240   _dbus_unlock (allocator->
lock);
   256       while (i < list->n_slots)
   289 #ifndef DBUS_DISABLE_ASSERT   294   if (!_dbus_lock (allocator->
lock))
   296         "before we allocated this slot");
   301   _dbus_unlock (allocator->
lock);
   322   while (i < list->n_slots)
   351 #ifdef DBUS_ENABLE_EMBEDDED_TESTS   352 #include "dbus-test.h"   355 static int free_counter;
   358 test_free_slot_data_func (
void *data)
   370 _dbus_data_slot_test (
void)
   392       dbus_int32_t tmp = -1;
   408                                      test_free_slot_data_func,
   409                                      &old_free_func, &old_data))
   428                                      test_free_slot_data_func,
   429                                      &old_free_func, &old_data))
   432       _dbus_assert (old_free_func == test_free_slot_data_func);
   435       (* old_free_func) (old_data);
   452       dbus_int32_t tmp = i;
 DBusFreeFunction free_data_func
Free the application data. 
#define NULL
A null pointer, defined appropriately for C or C++. 
void(* DBusFreeFunction)(void *memory)
The type of a function which frees a block of memory. 
int n_allocated_slots
number of slots malloc'd 
void * dbus_realloc(void *memory, size_t bytes)
Resizes a block of memory previously allocated by dbus_malloc() or dbus_malloc0(). 
void dbus_free(void *memory)
Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0(). 
An allocated slot for storing data. 
#define _dbus_assert(condition)
Aborts with an error message if the condition is false. 
#define _DBUS_INT_TO_POINTER(integer)
Safely stuffs an integer into a pointer, to be extracted later with _DBUS_POINTER_TO_INT. 
int n_used_slots
number of slots used 
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE. 
dbus_bool_t _dbus_data_slot_list_set(DBusDataSlotAllocator *allocator, DBusDataSlotList *list, int slot, void *data, DBusFreeFunction free_data_func, DBusFreeFunction *old_free_func, void **old_data)
Stores a pointer in the data slot list, along with an optional function to be used for freeing the da...
DBusDataSlot * slots
Data slots. 
#define _DBUS_POINTER_TO_INT(pointer)
Safely casts a void* to an integer; should only be used on void* that actually contain integers...
void _dbus_data_slot_list_clear(DBusDataSlotList *list)
Frees all data slots contained in the list, calling application-provided free functions if they exist...
dbus_int32_t slot_id
ID of this slot. 
void * _dbus_data_slot_list_get(DBusDataSlotAllocator *allocator, DBusDataSlotList *list, int slot)
Retrieves data previously set with _dbus_data_slot_list_set_data(). 
#define TRUE
Expands to "1". 
void _dbus_data_slot_list_init(DBusDataSlotList *list)
Initializes a slot list. 
#define _dbus_assert_not_reached(explanation)
Aborts with an error message if called. 
Data structure that stores the actual user data set at a given slot. 
An allocator that tracks a set of slot IDs. 
int refcount
Number of uses of the slot. 
int n_slots
Slots we have storage for in data_slots. 
#define FALSE
Expands to "0". 
void * data
The application data. 
dbus_bool_t _dbus_data_slot_allocator_init(DBusDataSlotAllocator *allocator, DBusGlobalLock lock)
Initializes a data slot allocator object, used to assign integer IDs for data slots. 
dbus_bool_t _dbus_data_slot_allocator_alloc(DBusDataSlotAllocator *allocator, dbus_int32_t *slot_id_p)
Allocates an integer ID to be used for storing data in a DBusDataSlotList. 
void _dbus_data_slot_allocator_free(DBusDataSlotAllocator *allocator, dbus_int32_t *slot_id_p)
Deallocates an ID previously allocated with _dbus_data_slot_allocator_alloc(). 
DBusAllocatedSlot * allocated_slots
Allocated slots. 
DBusDataSlot is used to store application data on the connection. 
DBusGlobalLock lock
index of thread lock 
void _dbus_data_slot_list_free(DBusDataSlotList *list)
Frees the data slot list and all data slots contained in it, calling application-provided free functi...