/* logic/retry_ctl.c — 见 retry_ctl.h 头注释(M10 离线重试节奏闸)。 */ #include "retry_ctl.h" void ncm_retry_ctl_init(ncm_retry_ctl *c) { if (!c) return; c->last_ms = 0; c->have_last = 0; } int ncm_retry_ctl_poll(ncm_retry_ctl *c, int offline, int busy, int64_t now_ms, int64_t interval_ms) { if (!c || interval_ms <= 0) return 0; if (!offline) return 0; /* 在线:不动基准 —— 抖动不得加速重试 */ if (busy) return 0; /* 单飞:上一个 worker 还在跑 */ if (!c->have_last) { /* 首次进离线:立即探测一次 */ c->have_last = 1; c->last_ms = now_ms; return 1; } if (now_ms < c->last_ms) { /* 时钟回退/异常:绝不让差值下溢成「巨大已超时」 */ c->last_ms = now_ms; /* 重定基准 → 仍需重新等满 interval */ return 0; } if (now_ms - c->last_ms < interval_ms) return 0; c->last_ms = now_ms; return 1; }