27#include "dbus-dataslot.h"
28#include "dbus-threads-internal.h"
29#include <dbus/dbus-test-tap.h>
55 allocator->
lock = lock;
73 dbus_int32_t *slot_id_p)
77 if (!_dbus_lock (allocator->
lock))
97 while (slot < allocator->n_allocated_slots)
137 _dbus_verbose (
"Allocated slot %d on allocator %p total %d slots allocated %d used\n",
141 _dbus_unlock (allocator->
lock);
158 dbus_int32_t *slot_id_p)
160 if (!_dbus_lock (allocator->
lock))
162 "before we allocated this slot");
164 _dbus_assert (*slot_id_p < allocator->n_allocated_slots);
172 _dbus_unlock (allocator->
lock);
177 _dbus_verbose (
"Freeing slot %d on allocator %p total %d allocated %d used\n",
192 _dbus_unlock (allocator->
lock);
232#ifndef DBUS_DISABLE_ASSERT
237 if (!_dbus_lock (allocator->
lock))
239 "before we allocated this slot");
243 _dbus_unlock (allocator->
lock);
259 while (i < list->n_slots)
292#ifndef DBUS_DISABLE_ASSERT
297 if (!_dbus_lock (allocator->
lock))
299 "before we allocated this slot");
304 _dbus_unlock (allocator->
lock);
325 while (i < list->n_slots)
354#ifdef DBUS_ENABLE_EMBEDDED_TESTS
355#include "dbus-test.h"
359static int free_counter;
362test_free_slot_data_func (
void *data)
374_dbus_data_slot_test (
const char *test_data_dir _DBUS_GNUC_UNUSED)
383 _dbus_test_fatal (
"no memory for allocator");
396 dbus_int32_t tmp = -1;
401 _dbus_test_fatal (
"did not allocate slots in numeric order");
412 test_free_slot_data_func,
413 &old_free_func, &old_data))
414 _dbus_test_fatal (
"no memory to set data");
432 test_free_slot_data_func,
433 &old_free_func, &old_data))
434 _dbus_test_fatal (
"no memory to set data");
436 _dbus_assert (old_free_func == test_free_slot_data_func);
439 (* old_free_func) (old_data);
456 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().
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.