wayland-util: add method for reserving new object id

wl_map_reserve_new() ensures that new id is valid and will point to an
empty array entry.
This commit is contained in:
Mathias Fiedler 2012-07-18 15:52:51 +02:00 committed by Kristian Høgsberg
parent 900e4b63ef
commit bfcd681930
2 changed files with 34 additions and 0 deletions

View file

@ -214,6 +214,39 @@ wl_map_insert_at(struct wl_map *map, uint32_t i, void *data)
return 0;
}
WL_EXPORT int
wl_map_reserve_new(struct wl_map *map, uint32_t i)
{
union map_entry *start;
uint32_t count;
struct wl_array *entries;
if (i < WL_SERVER_ID_START) {
entries = &map->client_entries;
} else {
entries = &map->server_entries;
i -= WL_SERVER_ID_START;
}
count = entries->size / sizeof *start;
if (count < i)
return -1;
if (count == i) {
wl_array_add(entries, sizeof *start);
start = entries->data;
start[i].data = NULL;
} else {
start = entries->data;
if (start[i].data != NULL) {
return -1;
}
}
return 0;
}
WL_EXPORT void
wl_map_remove(struct wl_map *map, uint32_t i)
{