[PATCH] wayland-util: merge {client, server}_entries in wl_map into one variable

Jason Ekstrand jason at jlekstrand.net
Mon Sep 9 08:52:11 PDT 2013


Chang,
This patch is, unfortunately, incorrect.  Yes, we have a side field that
tells us which side the wl_map was allocated for.  However, we use one
wl_map to store both client-side and server-side IDs.  The side field,
together with the WL_SERVER_ID_START, allow us to keep everything straight
in the two arrays.  If we replace them by one array, then the client-side
and server-side lists will overlap, conflict, and cause massive problems.
Thanks,
--Jason Ekstrand


On Sun, Sep 8, 2013 at 6:12 AM, Chang Liu <cl91tp at gmail.com> wrote:

> Since a wl_map can be either client side or server side (but not both)
> and we have the side field to indicate this, we can merge client_entries
> and server_entries into one variable to reduce clutter.
> ---
>  src/wayland-private.h |  3 +--
>  src/wayland-util.c    | 43 +++++++++++--------------------------------
>  2 files changed, 12 insertions(+), 34 deletions(-)
>
> diff --git a/src/wayland-private.h b/src/wayland-private.h
> index 5b3715d..68f4ee4 100644
> --- a/src/wayland-private.h
> +++ b/src/wayland-private.h
> @@ -60,8 +60,7 @@ enum wl_map_entry_flags {
>  };
>
>  struct wl_map {
> -       struct wl_array client_entries;
> -       struct wl_array server_entries;
> +       struct wl_array entries;
>         uint32_t side;
>         uint64_t free_list;
>  };
> diff --git a/src/wayland-util.c b/src/wayland-util.c
> index 1798fd6..2fc8b17 100644
> --- a/src/wayland-util.c
> +++ b/src/wayland-util.c
> @@ -167,22 +167,19 @@ wl_map_init(struct wl_map *map, uint32_t side)
>  WL_EXPORT void
>  wl_map_release(struct wl_map *map)
>  {
> -       wl_array_release(&map->client_entries);
> -       wl_array_release(&map->server_entries);
> +       wl_array_release(&map->entries);
>  }
>
>  WL_EXPORT uint32_t
>  wl_map_insert_new(struct wl_map *map, uint32_t flags, void *data)
>  {
>         union map_entry *start, *entry;
> -       struct wl_array *entries;
> +       struct wl_array *entries = &map->entries;
>         uint32_t base;
>
>         if (map->side == WL_MAP_CLIENT_SIDE) {
> -               entries = &map->client_entries;
>                 base = 0;
>         } else {
> -               entries = &map->server_entries;
>                 base = WL_SERVER_ID_START;
>         }
>
> @@ -208,12 +205,9 @@ wl_map_insert_at(struct wl_map *map, uint32_t flags,
> uint32_t i, void *data)
>  {
>         union map_entry *start;
>         uint32_t count;
> -       struct wl_array *entries;
> +       struct wl_array *entries = &map->entries;
>
> -       if (i < WL_SERVER_ID_START) {
> -               entries = &map->client_entries;
> -       } else {
> -               entries = &map->server_entries;
> +       if (i >= WL_SERVER_ID_START) {
>                 i -= WL_SERVER_ID_START;
>         }
>
> @@ -236,18 +230,14 @@ wl_map_reserve_new(struct wl_map *map, uint32_t i)
>  {
>         union map_entry *start;
>         uint32_t count;
> -       struct wl_array *entries;
> +       struct wl_array *entries = &map->entries;
>
>         if (i < WL_SERVER_ID_START) {
>                 if (map->side == WL_MAP_CLIENT_SIDE)
>                         return -1;
> -
> -               entries = &map->client_entries;
>         } else {
>                 if (map->side == WL_MAP_SERVER_SIDE)
>                         return -1;
> -
> -               entries = &map->server_entries;
>                 i -= WL_SERVER_ID_START;
>         }
>
> @@ -274,18 +264,14 @@ WL_EXPORT void
>  wl_map_remove(struct wl_map *map, uint32_t i)
>  {
>         union map_entry *start;
> -       struct wl_array *entries;
> +       struct wl_array *entries = &map->entries;
>
>         if (i < WL_SERVER_ID_START) {
>                 if (map->side == WL_MAP_SERVER_SIDE)
>                         return;
> -
> -               entries = &map->client_entries;
>         } else {
>                 if (map->side == WL_MAP_CLIENT_SIDE)
>                         return;
> -
> -               entries = &map->server_entries;
>                 i -= WL_SERVER_ID_START;
>         }
>
> @@ -299,12 +285,9 @@ wl_map_lookup(struct wl_map *map, uint32_t i)
>  {
>         union map_entry *start;
>         uint32_t count;
> -       struct wl_array *entries;
> +       struct wl_array *entries = &map->entries;
>
> -       if (i < WL_SERVER_ID_START) {
> -               entries = &map->client_entries;
> -       } else {
> -               entries = &map->server_entries;
> +       if (i >= WL_SERVER_ID_START) {
>                 i -= WL_SERVER_ID_START;
>         }
>
> @@ -322,12 +305,9 @@ wl_map_lookup_flags(struct wl_map *map, uint32_t i)
>  {
>         union map_entry *start;
>         uint32_t count;
> -       struct wl_array *entries;
> +       struct wl_array *entries = &map->entries;
>
> -       if (i < WL_SERVER_ID_START) {
> -               entries = &map->client_entries;
> -       } else {
> -               entries = &map->server_entries;
> +       if (i >= WL_SERVER_ID_START) {
>                 i -= WL_SERVER_ID_START;
>         }
>
> @@ -356,8 +336,7 @@ for_each_helper(struct wl_array *entries,
> wl_iterator_func_t func, void *data)
>  WL_EXPORT void
>  wl_map_for_each(struct wl_map *map, wl_iterator_func_t func, void *data)
>  {
> -       for_each_helper(&map->client_entries, func, data);
> -       for_each_helper(&map->server_entries, func, data);
> +       for_each_helper(&map->entries, func, data);
>  }
>
>  static void
> --
> 1.8.3.4
>
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/wayland-devel/attachments/20130909/9e122fd7/attachment-0001.html>


More information about the wayland-devel mailing list