lundi 28 décembre 2015

std::atomic

Can I use std::atomic<uint64_t> instead of sig_atomic_t in handler code?

My original code is below and i would like to upgrade 32 bit sig_atomic_t counter in order to handle periods longer than 596 hours of millisecond precision.

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);

Aucun commentaire:

Enregistrer un commentaire