我可以在处理程序代码中使用std::atomic<uint64_t>
代替sig_atomic_t
吗?
我的原始代码如下,我想升级32位sig_atomic_t计数器,以便处理超过596小时毫秒精度的时间段。
volatile static sig_atomic_t ms_long_counter;
static void MonotonicMsHandler(int sig, siginfo_t *si, void *uc) {
ms_long_counter += (1 + si->si_overrun);
}
///... Setup
struct sigaction sa;
sa.sa_flags = SA_RESTART | SA_SIGINFO;
sa.sa_sigaction = &MonotonicMsHandler;
sigemptyset(&sa.sa_mask);
sigaction(SIGRTMIN, &sa, NULL);
struct sigevent sev;
sev.sigev_notify = SIGEV_SIGNAL;
sev.sigev_signo = SIGRTMIN;
timer_create(CLOCK_MONOTONIC, &sev, &millis_timer);
struct itimerspec its;
its.it_value.tv_sec = 0;
its.it_value.tv_nsec = 1000000; // The first expiration in 1ms.
its.it_interval.tv_sec = its.it_value.tv_sec;
its.it_interval.tv_nsec = its.it_value.tv_nsec;
timer_settime(millis_timer, 0, &its, NULL);