View | Details | Raw Unified | Return to bug 115566
Collapse All | Expand All

(-)Util/Inotify.cs (-2 / +5 lines)
Lines 104-113 namespace Beagle.Util { Link Here
104
104
105
		[DllImport ("libinotifyglue")]
105
		[DllImport ("libinotifyglue")]
106
		static extern unsafe void inotify_snarf_events (int fd,
106
		static extern unsafe void inotify_snarf_events (int fd,
107
								int timeout_ms,
108
								out int nr,
107
								out int nr,
109
								out IntPtr buffer);
108
								out IntPtr buffer);
110
109
110
		[DllImport ("libinotifyglue")]
111
		static extern void inotify_snarf_cancel ();
112
111
		/////////////////////////////////////////////////////////////////////////////////////
113
		/////////////////////////////////////////////////////////////////////////////////////
112
114
113
		private class QueuedEvent {
115
		private class QueuedEvent {
Lines 455-460 namespace Beagle.Util { Link Here
455
				running = false;
457
				running = false;
456
				Monitor.Pulse (event_queue);
458
				Monitor.Pulse (event_queue);
457
			}
459
			}
460
461
			inotify_snarf_cancel ();
458
		}
462
		}
459
463
460
		static unsafe void SnarfWorker ()
464
		static unsafe void SnarfWorker ()
Lines 474-480 namespace Beagle.Util { Link Here
474
478
475
				// Will block while waiting for events, but with a 1s timeout.
479
				// Will block while waiting for events, but with a 1s timeout.
476
				inotify_snarf_events (inotify_fd, 
480
				inotify_snarf_events (inotify_fd, 
477
						      1000, 
478
						      out nr,
481
						      out nr,
479
						      out buffer);
482
						      out buffer);
480
483
(-)glue/inotify-glue.c (-3 / +22 lines)
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.

Return to bug 115566