PERFORCE change 123584 for review
Andrew Turner
andrew at FreeBSD.org
Mon Jul 16 11:29:56 UTC 2007
http://perforce.freebsd.org/chv.cgi?CH=123584
Change 123584 by andrew at andrew_hermies on 2007/07/16 11:29:13
When using kqueue to check for updates only check to directory that changed rather than all directories
Affected files ...
.. //depot/projects/soc2007/andrew-update/backend/facund-be.c#13 edit
Differences ...
==== //depot/projects/soc2007/andrew-update/backend/facund-be.c#13 (text+ko) ====
@@ -138,7 +138,7 @@
/* Create an event to look for files being added to the dir */
EV_SET(&events[pos], dir_fd[pos], EVFILT_VNODE, EV_ADD,
- NOTE_WRITE | NOTE_DELETE | NOTE_EXTEND, 0, NULL);
+ NOTE_WRITE | NOTE_DELETE | NOTE_EXTEND, 0, (void *)pos);
}
use_kqueue = 1;
@@ -150,13 +150,47 @@
kq = kqueue();
if (kq == -1)
use_kqueue = 0;
+
+ pos = dir_count;
+
+ /*
+ * This is the main loop to check for updates. It will
+ * either wait for file system activity on the update
+ * directories of just sleep for a fixed amount of time
+ * then scan all directories.
+ */
while(1) {
- for (pos = 0; base_dirs[pos] != NULL; pos++) {
- if (has_update(base_dirs[pos])) {
- printf("Updates found in %s\n", base_dirs[pos]);
- found_updates = 1;
+ assert(pos <= dir_count);
+ if (use_kqueue == 0 || pos == dir_count) {
+ /*
+ * We are using sleep to wait for updates or
+ * kqueue timed out. This means we have to check
+ * all directories to see if they have an update.
+ */
+ for (pos = 0; base_dirs[pos] != NULL; pos++) {
+ if (has_update(base_dirs[pos])) {
+ printf("Updates found in %s\n",
+ base_dirs[pos]);
+ found_updates = 1;
+ }
+ }
+ /* Check we have looked at all directories */
+ assert(pos == dir_count);
+ } else {
+ /*
+ * We are using kqueue to wait for updates.
+ * pos will contain the position in base_dirs of
+ * the directory that had file system activity.
+ */
+ if (pos < dir_count) {
+ if (has_update(base_dirs[pos])) {
+ printf("Updates found in %s\n",
+ base_dirs[pos]);
+ found_updates = 1;
+ }
}
}
+ pos = dir_count;
/*
* Wait for any disk activity to
@@ -170,9 +204,20 @@
/* Wait for posible updates */
if (use_kqueue == 1) {
/* Wait for posible updates ready to be installed */
- if (kevent(kq, events, dir_count, &changes, 1, &timeout)
- == -1) {
- use_kqueue = 1;
+ int error;
+
+ error = kevent(kq, events, dir_count, &changes, 1,
+ &timeout);
+
+ if (error == -1) {
+ /*
+ * There was an error in
+ * kqueue, change to sleep
+ */
+ use_kqueue = 0;
+ } else if (error > 0) {
+ /* Read in the item that changed */
+ pos = (size_t)changes.udata;
}
} else {
sleep(default_check_period);
More information about the p4-projects
mailing list