25 #include "dbus-dataslot.h" 26 #include "dbus-threads-internal.h" 27 #include <dbus/dbus-test-tap.h> 53 allocator->
lock = lock;
75 if (!_dbus_lock (allocator->
lock))
95 while (slot < allocator->n_allocated_slots)
135 _dbus_verbose (
"Allocated slot %d on allocator %p total %d slots allocated %d used\n",
139 _dbus_unlock (allocator->
lock);
158 if (!_dbus_lock (allocator->
lock))
160 "before we allocated this slot");
162 _dbus_assert (*slot_id_p < allocator->n_allocated_slots);
170 _dbus_unlock (allocator->
lock);
175 _dbus_verbose (
"Freeing slot %d on allocator %p total %d allocated %d used\n",
190 _dbus_unlock (allocator->
lock);
230 #ifndef DBUS_DISABLE_ASSERT 235 if (!_dbus_lock (allocator->
lock))
237 "before we allocated this slot");
241 _dbus_unlock (allocator->
lock);
257 while (i < list->n_slots)
290 #ifndef DBUS_DISABLE_ASSERT 295 if (!_dbus_lock (allocator->
lock))
297 "before we allocated this slot");
302 _dbus_unlock (allocator->
lock);
323 while (i < list->n_slots)
352 #ifdef DBUS_ENABLE_EMBEDDED_TESTS 353 #include "dbus-test.h" 356 static int free_counter;
359 test_free_slot_data_func (
void *data)
371 _dbus_data_slot_test (
void)
380 _dbus_test_fatal (
"no memory for allocator");
398 _dbus_test_fatal (
"did not allocate slots in numeric order");
409 test_free_slot_data_func,
410 &old_free_func, &old_data))
411 _dbus_test_fatal (
"no memory to set data");
429 test_free_slot_data_func,
430 &old_free_func, &old_data))
431 _dbus_test_fatal (
"no memory to set data");
433 _dbus_assert (old_free_func == test_free_slot_data_func);
436 (* old_free_func) (old_data);
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_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_realloc(void *memory, size_t bytes)
Resizes a block of memory previously allocated by dbus_malloc() or dbus_malloc0().
int dbus_int32_t
A 32-bit signed integer on all platforms.
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...