feat: rename delaymgr precision→precision_ms, replace sleep() with nanosleep() (P0-2b)

- Rename `precision` field to `precision_ms` in delaymgr_t struct (delay.h)
- Replace `sleep(mgr->precision)` with `nanosleep()` for 10ms granularity (delay.c)
- Add `#include <time.h>` to delay.c (already in delay.h)
- Update delaymgr_init() to store precision_ms parameter
- Update all call sites: cluster.c (2→200ms), controller/testsuite/test.c (2→2000ms),
  lib/testsuite/test_delay.c (1→1000ms)
- Add TDD test test_delaymgr_precision_ms_field verifying field exists and stores correctly
- delay_task() delay parameter remains in seconds; only sleep granularity changes
This commit is contained in:
Rongsong Shen 2026-05-07 09:08:03 +00:00
parent 762b59c043
commit 6d4d8eb81d
5 changed files with 23 additions and 6 deletions

View file

@ -3,6 +3,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "delay.h"
#include "utils.h"
@ -17,7 +18,10 @@ static void* delay_worker(void* args)
time_t now;
pthread_testcancel();
sleep(mgr->precision);
{
struct timespec ts = { 0, (long)mgr->precision_ms * 1000000L };
nanosleep(&ts, NULL);
}
it = ordq_peek(&(mgr->tasks), NULL);
if (it == NULL) {
@ -100,7 +104,7 @@ int delaymgr_init(delaymgr_t* mgr, int precision, task_run_fn_t runner_fn)
runner_fn = default_runner_fn;
}
mgr->precision = precision;
mgr->precision_ms = precision;
mgr->running = 0;
mgr->runner_fn = runner_fn;
mgr->worker = 0;