Re: [PATCH 13/14] tools lib fd array: Allow associating an integer cookie with each entry

From: Jiri Olsa
Date: Thu Sep 11 2014 - 06:33:48 EST


On Wed, Sep 10, 2014 at 11:08:48AM -0300, Arnaldo Carvalho de Melo wrote:

SNIP

> }
>
> -int fdarray__filter(struct fdarray *fda, short revents)
> +int fdarray__filter(struct fdarray *fda, short revents,
> + void (*entry_destructor)(struct fdarray *fda, int fd))
> {
> int fd, nr = 0;
>
> @@ -80,11 +94,17 @@ int fdarray__filter(struct fdarray *fda, short revents)
> return 0;
>
> for (fd = 0; fd < fda->nr; ++fd) {
> - if (fda->entries[fd].revents & revents)
> + if (fda->entries[fd].revents & revents) {
> + if (entry_destructor)
> + entry_destructor(fda, fd);

the desctructor callback could have the 'priv' as an argument
so we dont need to touch fdarray internals in upper layer

> +
> continue;
> + }
>
> - if (fd != nr)
> + if (fd != nr) {
> fda->entries[nr] = fda->entries[fd];
> + fda->priv[nr] = fda->priv[fd];
> + }
>
> ++nr;
> }
> diff --git a/tools/lib/api/fd/array.h b/tools/lib/api/fd/array.h
> index de38361ba69e..7b2870a96898 100644
> --- a/tools/lib/api/fd/array.h
> +++ b/tools/lib/api/fd/array.h
> @@ -10,6 +10,7 @@ struct fdarray {
> int nr_alloc;
> int nr_autogrow;
> struct pollfd *entries;
> + int *priv;

I like the idea of private pointer for each fd, but I think
it should be 'void*' to keep the library generic. The 'int*'
is related only to the evlist usage of this.

jirka
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/