mirror of
https://github.com/torvalds/linux.git
synced 2026-10-07 22:37:45 -04:00
We will use this in perf's evlist class so that it can, at
fdarray__filter() time, to unmap the associated ring buffer.
We may need to have further info associated with each fdarray entry, in
that case we'll make that int array a 'union fdarray_priv' one and put a
pointer there so that users can stash whatever they want there. For now,
an int is enough tho.
v2: Add clarification to the per array entry priv area, as well as make
it a union, which makes usage a bit longer, but if/when we make it
use more space by allowing per entry pointers existing users source
code will not have to be changed, just rebuilt.
Cc: Adrian Hunter <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Corey Ashford <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Jean Pihet <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
Link: http://lkml.kernel.org/n/[email protected]
47 lines
1.3 KiB
C
47 lines
1.3 KiB
C
#ifndef __API_FD_ARRAY__
|
|
#define __API_FD_ARRAY__
|
|
|
|
#include <stdio.h>
|
|
|
|
struct pollfd;
|
|
|
|
/**
|
|
* struct fdarray: Array of file descriptors
|
|
*
|
|
* @priv: Per array entry priv area, users should access just its contents,
|
|
* not set it to anything, as it is kept in synch with @entries, being
|
|
* realloc'ed, * for instance, in fdarray__{grow,filter}.
|
|
*
|
|
* I.e. using 'fda->priv[N].idx = * value' where N < fda->nr is ok,
|
|
* but doing 'fda->priv = malloc(M)' is not allowed.
|
|
*/
|
|
struct fdarray {
|
|
int nr;
|
|
int nr_alloc;
|
|
int nr_autogrow;
|
|
struct pollfd *entries;
|
|
union {
|
|
int idx;
|
|
} *priv;
|
|
};
|
|
|
|
void fdarray__init(struct fdarray *fda, int nr_autogrow);
|
|
void fdarray__exit(struct fdarray *fda);
|
|
|
|
struct fdarray *fdarray__new(int nr_alloc, int nr_autogrow);
|
|
void fdarray__delete(struct fdarray *fda);
|
|
|
|
int fdarray__add(struct fdarray *fda, int fd, short revents);
|
|
int fdarray__poll(struct fdarray *fda, int timeout);
|
|
int fdarray__filter(struct fdarray *fda, short revents,
|
|
void (*entry_destructor)(struct fdarray *fda, int fd));
|
|
int fdarray__grow(struct fdarray *fda, int extra);
|
|
int fdarray__fprintf(struct fdarray *fda, FILE *fp);
|
|
|
|
static inline int fdarray__available_entries(struct fdarray *fda)
|
|
{
|
|
return fda->nr_alloc - fda->nr;
|
|
}
|
|
|
|
#endif /* __API_FD_ARRAY__ */
|