|
Lines 1-3
Link Here
|
|
|
1 |
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ |
| 2 |
|
| 1 |
/* |
3 |
/* |
| 2 |
* inotify-glue.c |
4 |
* inotify-glue.c |
| 3 |
* |
5 |
* |
|
Lines 49-54
static int max_user_instances = 8;
Link Here
|
| 49 |
static int max_user_watches = 8192; |
51 |
static int max_user_watches = 8192; |
| 50 |
static int max_queued_events = 256; |
52 |
static int max_queued_events = 256; |
| 51 |
|
53 |
|
|
|
54 |
static int snarf_cancellation_pipe [2]; |
| 55 |
|
| 52 |
/* Paranoid code to read an integer from a sysfs (well, any) file. */ |
56 |
/* Paranoid code to read an integer from a sysfs (well, any) file. */ |
| 53 |
static void |
57 |
static void |
| 54 |
read_int (const char *filename, int *var) |
58 |
read_int (const char *filename, int *var) |
|
Lines 87-92
inotify_glue_init (void)
Link Here
|
| 87 |
"enabled."); |
91 |
"enabled."); |
| 88 |
} |
92 |
} |
| 89 |
|
93 |
|
|
|
94 |
if (pipe (snarf_cancellation_pipe) == -1) |
| 95 |
perror ("Can't create snarf_cancellation_pipe"); |
| 96 |
|
| 90 |
read_int (PROCFS_MAX_USER_DEVICES, &max_user_instances); |
97 |
read_int (PROCFS_MAX_USER_DEVICES, &max_user_instances); |
| 91 |
read_int (PROCFS_MAX_USER_WATCHES, &max_user_watches); |
98 |
read_int (PROCFS_MAX_USER_WATCHES, &max_user_watches); |
| 92 |
read_int (PROCFS_MAX_QUEUED_EVENTS, &max_queued_events); |
99 |
read_int (PROCFS_MAX_QUEUED_EVENTS, &max_queued_events); |
|
Lines 125-130
inotify_glue_ignore (int fd, __u32 wd)
Link Here
|
| 125 |
return ret; |
132 |
return ret; |
| 126 |
} |
133 |
} |
| 127 |
|
134 |
|
|
|
135 |
void |
| 136 |
inotify_snarf_cancel () |
| 137 |
{ |
| 138 |
write (snarf_cancellation_pipe [1], |
| 139 |
&snarf_cancellation_pipe, 1); // write a convenient byte |
| 140 |
} |
| 141 |
|
| 128 |
|
142 |
|
| 129 |
#define MAX_PENDING_COUNT 5 |
143 |
#define MAX_PENDING_COUNT 5 |
| 130 |
#define PENDING_PAUSE_NANOSECONDS 2000000 |
144 |
#define PENDING_PAUSE_NANOSECONDS 2000000 |
|
Lines 132-140
inotify_glue_ignore (int fd, __u32 wd)
Link Here
|
| 132 |
#define PENDING_MARGINAL_COST(p) ((unsigned int) (1 << (p))) |
146 |
#define PENDING_MARGINAL_COST(p) ((unsigned int) (1 << (p))) |
| 133 |
|
147 |
|
| 134 |
void |
148 |
void |
| 135 |
inotify_snarf_events (int fd, int timeout_ms, int *nr, void **buffer_out) |
149 |
inotify_snarf_events (int fd, int *nr, void **buffer_out) |
| 136 |
{ |
150 |
{ |
| 137 |
struct pollfd pollfd = { fd, POLLIN | POLLPRI, 0 }; |
151 |
struct pollfd pollfd [2] = { { fd, POLLIN | POLLPRI, 0 }, { snarf_cancellation_pipe [0], POLLIN, 0} }; |
| 138 |
unsigned int prev_pending = 0, pending_count = 0; |
152 |
unsigned int prev_pending = 0, pending_count = 0; |
| 139 |
static struct inotify_event *buffer = NULL; |
153 |
static struct inotify_event *buffer = NULL; |
| 140 |
static size_t buffer_size; |
154 |
static size_t buffer_size; |
|
Lines 158-169
inotify_snarf_events (int fd, int timeou
Link Here
|
| 158 |
*nr = 0; |
172 |
*nr = 0; |
| 159 |
|
173 |
|
| 160 |
/* Wait for the file descriptor to be ready to read. */ |
174 |
/* Wait for the file descriptor to be ready to read. */ |
| 161 |
ret = poll (&pollfd, 1, timeout_ms); |
175 |
ret = poll (pollfd, 2, -1); |
| 162 |
if (ret == -1) { |
176 |
if (ret == -1) { |
| 163 |
if (errno != EINTR) |
177 |
if (errno != EINTR) |
| 164 |
perror ("poll"); |
178 |
perror ("poll"); |
| 165 |
return; |
179 |
return; |
| 166 |
} else if (ret == 0) |
180 |
} else if (ret == 0) |
|
|
181 |
return; |
| 182 |
|
| 183 |
/* Return immediately if something happened on the |
| 184 |
snarf cancellation pipe. */ |
| 185 |
if (pollfd [1].revents != 0) |
| 167 |
return; |
186 |
return; |
| 168 |
|
187 |
|
| 169 |
/* Reading events in groups significantly helps performance. |
188 |
/* Reading events in groups significantly helps performance. |