| 716 | } |
| 717 | |
| 718 | int cbm_watcher_run(cbm_watcher_t *w, int base_interval_ms) { |
| 719 | if (!w) { |
| 720 | return CBM_NOT_FOUND; |
| 721 | } |
| 722 | if (base_interval_ms <= 0) { |
| 723 | base_interval_ms = POLL_BASE_MS; |
| 724 | } |
| 725 | |
| 726 | cbm_log_info("watcher.start", "interval_ms", base_interval_ms > 999 ? "multi-sec" : "fast"); |
| 727 | |
| 728 | while (!atomic_load(&w->stopped)) { |
| 729 | cbm_watcher_poll_once(w); |
| 730 | |
| 731 | /* Sleep in small increments to allow responsive shutdown */ |
| 732 | int slept = 0; |
| 733 | while (slept < base_interval_ms && !atomic_load(&w->stopped)) { |
| 734 | int chunk = base_interval_ms - slept; |
| 735 | if (chunk > SLEEP_CHUNK_MS) { |
| 736 | chunk = SLEEP_CHUNK_MS; |
| 737 | } |
| 738 | cbm_usleep((unsigned)chunk * CBM_MSEC_PER_SEC); |
| 739 | slept += chunk; |
| 740 | } |
| 741 | } |
| 742 | |
| 743 | cbm_log_info("watcher.stop"); |
| 744 | return 0; |
| 745 | } |
no test coverage detected