diff options
author | Mathias Fiedler <mathias.fiedler@xse.de> | 2012-07-18 15:52:51 +0200 |
---|---|---|
committer | Kristian Høgsberg <krh@bitplanet.net> | 2012-07-22 14:09:48 -0400 |
commit | bfcd6819303b0304ba38d57af4856eb6db286907 (patch) | |
tree | 57323623e7ac0678c73da82dd6e9a7b0e14cd5a8 | |
parent | 900e4b63ef185767a4f1f1eea0ea1fb9899b4da5 (diff) |
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.
-rw-r--r-- | src/wayland-private.h | 1 | ||||
-rw-r--r-- | src/wayland-util.c | 33 |
2 files changed, 34 insertions, 0 deletions
diff --git a/src/wayland-private.h b/src/wayland-private.h index ea70258..2113d83 100644 --- a/src/wayland-private.h +++ b/src/wayland-private.h @@ -46,6 +46,7 @@ void wl_map_init(struct wl_map *map); void wl_map_release(struct wl_map *map); uint32_t wl_map_insert_new(struct wl_map *map, uint32_t side, void *data); int wl_map_insert_at(struct wl_map *map, uint32_t i, void *data); +int wl_map_reserve_new(struct wl_map *map, uint32_t i); void wl_map_remove(struct wl_map *map, uint32_t i); void *wl_map_lookup(struct wl_map *map, uint32_t i); void wl_map_for_each(struct wl_map *map, wl_iterator_func_t func, void *data); diff --git a/src/wayland-util.c b/src/wayland-util.c index 107b6db..eacf902 100644 --- a/src/wayland-util.c +++ b/src/wayland-util.c @@ -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) { |