From owner-p4-projects@FreeBSD.ORG Mon Jul 16 11:29:56 2007 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 4FA2F16A404; Mon, 16 Jul 2007 11:29:56 +0000 (UTC) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 2649B16A401 for ; Mon, 16 Jul 2007 11:29:56 +0000 (UTC) (envelope-from andrew@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [69.147.83.41]) by mx1.freebsd.org (Postfix) with ESMTP id F289E13C471 for ; Mon, 16 Jul 2007 11:29:55 +0000 (UTC) (envelope-from andrew@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id l6GBTtAU068085 for ; Mon, 16 Jul 2007 11:29:55 GMT (envelope-from andrew@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id l6GBTtmQ068082 for perforce@freebsd.org; Mon, 16 Jul 2007 11:29:55 GMT (envelope-from andrew@freebsd.org) Date: Mon, 16 Jul 2007 11:29:55 GMT Message-Id: <200707161129.l6GBTtmQ068082@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to andrew@freebsd.org using -f From: Andrew Turner To: Perforce Change Reviews Cc: Subject: PERFORCE change 123584 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Jul 2007 11:29:56 -0000 http://perforce.freebsd.org/chv.cgi?CH=123584 Change 123584 by andrew@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);