25 #include "dbus-dataslot.h"
26 #include "dbus-threads-internal.h"
82 else if (allocator->
lock_loc != mutex_loc)
84 _dbus_warn_check_failed (
"D-Bus threads were initialized after first using the D-Bus library. If your application does not directly initialize threads or use D-Bus, keep in mind that some library or plugin may have used D-Bus or initialized threads behind your back. You can often fix this problem by calling dbus_init_threads() or dbus_g_threads_init() early in your main() method, before D-Bus is used.\n");
105 while (slot < allocator->n_allocated_slots)
145 _dbus_verbose (
"Allocated slot %d on allocator %p total %d slots allocated %d used\n",
170 _dbus_assert (*slot_id_p < allocator->n_allocated_slots);
183 _dbus_verbose (
"Freeing slot %d on allocator %p total %d allocated %d used\n",
245 #ifndef DBUS_DISABLE_ASSERT
269 while (i < list->n_slots)
302 #ifndef DBUS_DISABLE_ASSERT
332 while (i < list->n_slots)
361 #ifdef DBUS_BUILD_TESTS
362 #include "dbus-test.h"
365 static int free_counter;
368 test_free_slot_data_func (
void *data)
380 _dbus_data_slot_test (
void)
423 test_free_slot_data_func,
424 &old_free_func, &old_data))
443 test_free_slot_data_func,
444 &old_free_func, &old_data))
447 _dbus_assert (old_free_func == test_free_slot_data_func);
450 (* 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_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.
dbus_bool_t _dbus_data_slot_allocator_init(DBusDataSlotAllocator *allocator)
Initializes a data slot allocator object, used to assign integer IDs for data slots.
#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.
void _dbus_warn_check_failed(const char *format,...)
Prints a "critical" warning to stderr when an assertion fails; differs from _dbus_warn primarily in t...
void _dbus_rmutex_new_at_location(DBusRMutex **location_p)
Creates a new mutex or creates a no-op mutex if threads are not initialized.
dbus_bool_t _dbus_data_slot_allocator_alloc(DBusDataSlotAllocator *allocator, DBusRMutex **mutex_loc, dbus_int32_t *slot_id_p)
Allocates an integer ID to be used for storing data in a DBusDataSlotList.
int n_used_slots
number of slots used
void _dbus_rmutex_unlock(DBusRMutex *mutex)
Unlocks a mutex.
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.
void _dbus_rmutex_free_at_location(DBusRMutex **location_p)
Frees a DBusRMutex or removes it from the uninitialized mutex list; does nothing if passed a NULL poi...
int n_slots
Slots we have storage for in data_slots.
void _dbus_rmutex_lock(DBusRMutex *mutex)
Locks a mutex.
#define FALSE
Expands to "0".
void * data
The application data.
DBusRMutex ** lock_loc
location of thread lock
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.
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...