Lines Matching refs:allocator

40  * Initializes a data slot allocator object, used to assign
43 * @param allocator the allocator to initialize
46 _dbus_data_slot_allocator_init (DBusDataSlotAllocator *allocator)
48 allocator->allocated_slots = NULL;
49 allocator->n_allocated_slots = 0;
50 allocator->n_used_slots = 0;
51 allocator->lock_loc = NULL;
63 * @param allocator the allocator
64 * @param mutex_loc the location lock for this allocator
69 _dbus_data_slot_allocator_alloc (DBusDataSlotAllocator *allocator,
77 if (allocator->n_allocated_slots == 0)
79 _dbus_assert (allocator->lock_loc == NULL);
80 allocator->lock_loc = mutex_loc;
82 else if (allocator->lock_loc != mutex_loc)
92 _dbus_assert (slot < allocator->n_allocated_slots);
93 _dbus_assert (allocator->allocated_slots[slot].slot_id == slot);
95 allocator->allocated_slots[slot].refcount += 1;
102 if (allocator->n_used_slots < allocator->n_allocated_slots)
105 while (slot < allocator->n_allocated_slots)
107 if (allocator->allocated_slots[slot].slot_id < 0)
109 allocator->allocated_slots[slot].slot_id = slot;
110 allocator->allocated_slots[slot].refcount = 1;
111 allocator->n_used_slots += 1;
117 _dbus_assert (slot < allocator->n_allocated_slots);
124 tmp = dbus_realloc (allocator->allocated_slots,
125 sizeof (DBusAllocatedSlot) * (allocator->n_allocated_slots + 1));
129 allocator->allocated_slots = tmp;
130 slot = allocator->n_allocated_slots;
131 allocator->n_allocated_slots += 1;
132 allocator->n_used_slots += 1;
133 allocator->allocated_slots[slot].slot_id = slot;
134 allocator->allocated_slots[slot].refcount = 1;
138 _dbus_assert (slot < allocator->n_allocated_slots);
140 _dbus_assert (allocator->allocated_slots[slot].slot_id == slot);
141 _dbus_assert (allocator->allocated_slots[slot].refcount == 1);
145 _dbus_verbose ("Allocated slot %d on allocator %p total %d slots allocated %d used\n",
146 slot, allocator, allocator->n_allocated_slots, allocator->n_used_slots);
149 _dbus_mutex_unlock (*(allocator->lock_loc));
161 * @param allocator the allocator
165 _dbus_data_slot_allocator_free (DBusDataSlotAllocator *allocator,
168 _dbus_mutex_lock (*(allocator->lock_loc));
170 _dbus_assert (*slot_id_p < allocator->n_allocated_slots);
171 _dbus_assert (allocator->allocated_slots[*slot_id_p].slot_id == *slot_id_p);
172 _dbus_assert (allocator->allocated_slots[*slot_id_p].refcount > 0);
174 allocator->allocated_slots[*slot_id_p].refcount -= 1;
176 if (allocator->allocated_slots[*slot_id_p].refcount > 0)
178 _dbus_mutex_unlock (*(allocator->lock_loc));
183 _dbus_verbose ("Freeing slot %d on allocator %p total %d allocated %d used\n",
184 *slot_id_p, allocator, allocator->n_allocated_slots, allocator->n_used_slots);
186 allocator->allocated_slots[*slot_id_p].slot_id = -1;
189 allocator->n_used_slots -= 1;
191 if (allocator->n_used_slots == 0)
193 DBusMutex **mutex_loc = allocator->lock_loc;
195 dbus_free (allocator->allocated_slots);
196 allocator->allocated_slots = NULL;
197 allocator->n_allocated_slots = 0;
198 allocator->lock_loc = NULL;
204 _dbus_mutex_unlock (*(allocator->lock_loc));
224 * same allocator passed in here. The same allocator has to be used
227 * @param allocator the allocator to use
237 _dbus_data_slot_list_set (DBusDataSlotAllocator *allocator,
246 /* We need to take the allocator lock here, because the allocator could
250 _dbus_mutex_lock (*(allocator->lock_loc));
251 _dbus_assert (slot < allocator->n_allocated_slots);
252 _dbus_assert (allocator->allocated_slots[slot].slot_id == slot);
253 _dbus_mutex_unlock (*(allocator->lock_loc));
292 * @param allocator the allocator slot was allocated from
298 _dbus_data_slot_list_get (DBusDataSlotAllocator *allocator,
303 /* We need to take the allocator lock here, because the allocator could
307 _dbus_mutex_lock (*(allocator->lock_loc));
309 _dbus_assert (slot < allocator->n_allocated_slots);
310 _dbus_assert (allocator->allocated_slots[slot].slot_id == slot);
311 _dbus_mutex_unlock (*(allocator->lock_loc));
382 DBusDataSlotAllocator allocator;
389 if (!_dbus_data_slot_allocator_init (&allocator))
390 _dbus_assert_not_reached ("no memory for allocator");
409 _dbus_data_slot_allocator_alloc (&allocator, &mutex, &tmp);
420 if (!_dbus_data_slot_list_set (&allocator, &list,
430 _dbus_assert (_dbus_data_slot_list_get (&allocator, &list, i) ==
440 if (!_dbus_data_slot_list_set (&allocator, &list,
453 _dbus_assert (_dbus_data_slot_list_get (&allocator, &list, i) ==
469 _dbus_data_slot_allocator_free (&allocator, &tmp);