+ if (mport->cfm) {
+ cfm_run(mport->cfm);
+ cfm_wait(mport->cfm);
+ }
+ if (mport->bfd) {
+ bfd_run(mport->bfd);
+ bfd_wait(mport->bfd);
+ }
+ /* Computes the next wakeup time for this mport. */
+ next_wake_time = MIN(bfd_wake_time(mport->bfd),
+ cfm_wake_time(mport->cfm));
+ heap_change(&monitor_heap, &mport->heap_node,
+ MSEC_TO_PRIO(next_wake_time));
+ }
+
+ /* Waits on the earliest next wakeup time. */
+ if (!heap_is_empty(&monitor_heap)) {
+ long long int next_timeout, next_mport_wakeup;
+
+ next_timeout = time_msec() + MONITOR_INTERVAL_MSEC;
+ next_mport_wakeup = PRIO_TO_MSEC(heap_max(&monitor_heap)->priority);
+ poll_timer_wait_until(MIN(next_timeout, next_mport_wakeup));