Branch: Tag:

2009-08-06

2009-08-06 11:53:01 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Added support for limiting the number of paths to check in a single call of check().

Rev: lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike:1.21

1:   //   // Basic filesystem monitor.   // - // $Id: basic.pike,v 1.20 2009/08/05 13:06:15 grubba Exp $ + // $Id: basic.pike,v 1.21 2009/08/06 11:53:01 grubba Exp $   //   // 2009-07-09 Henrik Grubbström   //
656:   //! Maximum time in seconds to wait for changes. @expr{-1@}   //! for infinite wait.   //! + //! @param max_cnt + //! Maximum number of paths to check in this call. @expr{0@} + //! (zero) for unlimited. + //!   //! A suitable subset of the monitored files will be checked   //! for changes.   //!
670:   //!   //! @seealso   //! @[monitor()] - int check(int|void max_wait) + int check(int|void max_wait, int|void max_cnt)   {    while(1) {    int ret = max_dir_check_interval;
681:    while ((m = monitor_queue->peek()) &&    m <= t) {    cnt += check_monitor(m); +  if (!--max_cnt) break;    }    if (m) {    ret = m->next_poll - t;    if (ret <= 0) ret = 1; -  +  } else { +  max_cnt--;    }    } -  if (cnt || !max_wait) return ret; +  if (cnt || !max_wait || !max_cnt) return ret;    if (ret < max_wait) {    max_wait -= ret;    sleep(ret);