pike.git / lib / modules / Filesystem.pmod / Monitor.pmod / basic.pike

version» Context lines:

pike.git/lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike:1664:    co_id = 0;       int t;    mixed err = catch {    t = check(0);    };    set_nonblocking(t);    if (err) throw(err);   }    + //! Reschedule beckend check. + //! + //! @param suggested_t + //! Suggested time in seconds until next call of @[check()]. + //! + //! Register suitable callbacks with the backend to automatically + //! call @[check()]. + //! + //! @[check()] and thus all the callbacks will be called from the + //! backend thread. + protected void reschedule_backend_check(int|void suggested_t) + { +  // NB: Other stuff than plain files may be used with the monitoring +  // system, so the call_out may be needed even with accelerators. +  // +  // NB: Also note that Inotify doesn't support monitoring of non-existing +  // paths, so it still needs the call_out-loop. +  MON_WERR("Rescheduling call_out.\n"); +  +  int t = max_dir_check_interval; +  if (sizeof(monitor_queue)) { +  Monitor m = monitor_queue->peek(); +  if (m) { +  t = m->next_poll - time(1); +  } +  if (t > max_dir_check_interval) t = max_dir_check_interval; +  } +  if (!undefinedp(suggested_t) && (suggested_t < t)) { +  t = suggested_t; +  } +  if (t < 0) t = 0; +  +  if (co_id) { +  if (backend) backend->remove_call_out(co_id); +  else remove_call_out(co_id); +  } +  if (backend) co_id = backend->call_out(backend_check, t); +  else co_id = call_out(backend_check, t); + } +    //! Turn on nonblocking mode.   //! - //! @param t + //! @param suggested_t   //! Suggested time in seconds until next call of @[check()].   //!   //! Register suitable callbacks with the backend to automatically   //! call @[check()].   //!   //! @[check()] and thus all the callbacks will be called from the   //! backend thread.   //!   //! @note   //! If nonblocking mode is already active, this function will   //! be a noop.   //!   //! @seealso   //! @[set_blocking()], @[check()]. - void set_nonblocking(int|void t) + void set_nonblocking(int|void suggested_t)   {   #if HAVE_INOTIFY    if (instance) {    instance->set_nonblocking();    }   #endif    if (co_id) return; -  // NB: Other stuff than plain files may be used with the monitoring -  // system, so the call_out may be needed even with accelerators. -  // -  // NB: Also note that Inotify doesn't support monitoring of non-existing -  // paths, so it still needs the call_out-loop. -  if (undefinedp(t)) { -  if (sizeof(monitor_queue)) { -  Monitor m = monitor_queue->peek(); -  t = (m && m->next_poll - time(1)) || max_dir_check_interval; -  } else { -  t = max_dir_check_interval; +  reschedule_backend_check(suggested_t);   } -  if (t > max_dir_check_interval) t = max_dir_check_interval; -  if (t < 0) t = 0; -  } -  if (backend) co_id = backend->call_out(backend_check, t); -  else co_id = call_out(backend_check, t); - } +       //! Set the @[default_max_dir_check_interval].   void set_max_dir_check_interval(int max_dir_check_interval)   {    if (max_dir_check_interval > 0) {    this::max_dir_check_interval = max_dir_check_interval;    } else {    this::max_dir_check_interval = default_max_dir_check_interval;    }   }