25#include "dbus-dataslot.h"
26#include "dbus-threads-internal.h"
27#include <dbus/dbus-test-tap.h>
53 allocator->
lock = lock;
71 dbus_int32_t *slot_id_p)
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);
156 dbus_int32_t *slot_id_p)
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"
357static int free_counter;
360test_free_slot_data_func (
void *data)
372_dbus_data_slot_test (
const char *test_data_dir _DBUS_GNUC_UNUSED)
381 _dbus_test_fatal (
"no memory for allocator");
394 dbus_int32_t tmp = -1;
399 _dbus_test_fatal (
"did not allocate slots in numeric order");
410 test_free_slot_data_func,
411 &old_free_func, &old_data))
412 _dbus_test_fatal (
"no memory to set data");
430 test_free_slot_data_func,
431 &old_free_func, &old_data))
432 _dbus_test_fatal (
"no memory to set data");
434 _dbus_assert (old_free_func == test_free_slot_data_func);
437 (* old_free_func) (old_data);
454 dbus_int32_t tmp = i;
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().
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_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.
void _dbus_data_slot_list_init(DBusDataSlotList *list)
Initializes a slot list.
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...
void * _dbus_data_slot_list_get(DBusDataSlotAllocator *allocator, DBusDataSlotList *list, int slot)
Retrieves data previously set with _dbus_data_slot_list_set_data().
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...
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.
#define _DBUS_INT_TO_POINTER(integer)
Safely stuffs an integer into a pointer, to be extracted later with _DBUS_POINTER_TO_INT.
#define _dbus_assert_not_reached(explanation)
Aborts with an error message if called.
#define _dbus_assert(condition)
Aborts with an error message if the condition is false.
#define _DBUS_POINTER_TO_INT(pointer)
Safely casts a void* to an integer; should only be used on void* that actually contain integers,...
#define NULL
A null pointer, defined appropriately for C or C++.
#define TRUE
Expands to "1".
#define FALSE
Expands to "0".
void(* DBusFreeFunction)(void *memory)
The type of a function which frees a block of memory.
void dbus_free(void *memory)
Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().
void * dbus_realloc(void *memory, size_t bytes)
Resizes a block of memory previously allocated by dbus_malloc() or dbus_malloc0().
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
An allocated slot for storing data.
int refcount
Number of uses of the slot.
dbus_int32_t slot_id
ID of this slot.
An allocator that tracks a set of slot IDs.
DBusAllocatedSlot * allocated_slots
Allocated slots.
int n_allocated_slots
number of slots malloc'd
DBusGlobalLock lock
index of thread lock
int n_used_slots
number of slots used
Data structure that stores the actual user data set at a given slot.
int n_slots
Slots we have storage for in data_slots.
DBusDataSlot * slots
Data slots.
DBusDataSlot is used to store application data on the connection.
void * data
The application data.
DBusFreeFunction free_data_func
Free the application data.