Linux timers and real-time signals



  • There are several timers that generate the same SIGRTMIN signal, adding to sival_int. There are some timer signal processors. Do I understand correctly that the signal will reach all the signal processors? What if the signal is generated at the same time by several timers?

    Is it correct in the processor to check sival_int?

    #define TIMER_EVENT_ID_1 1
    #define TIMER_EVENT_ID_2 2
    

    void timer_handler(int signo, siginfo_t *info, void *context)
    {
    if(info->si_value.sival_int==TIMER_EVENT_ID_1)
    {
    sem_post(&sem1); //будим трид
    }

    if(info->si_value.sival_int==TIMER_EVENT_ID_2)
    {
        sem_post(&sem2); //будим трид 
    }
    

    }

    In different flows, I create, and then I drop and set the timers:

    typedef struct
    {
    struct sigevent sigev;
    struct sigaction sa;
    struct itimerspec ival;
    timer_t tid;
    } timer_data_t;

    int init_timer(timer_data_t *timer_data, void *handler, UNS8 sigNum, UNS8 eventNum)
    {
    timer_data->sa.sa_flags = SA_SIGINFO;
    sigemptyset(&timer_data->sa.sa_mask);
    sigaddset(&timer_data->sa.sa_mask, sigNum);
    timer_data->sa.sa_sigaction=handler;

    if(sigaction(sigNum, &timer_data->sa, NULL)==-1)
    {
        perror("sigaction failed");
        return -1;
    }
    
    timer_data->sigev.sigev_notify = SIGEV_SIGNAL;
    timer_data->sigev.sigev_signo = sigNum;
    timer_data->sigev.sigev_value.sival_int=eventNum;
    
    //создаем таймер
    if( timer_create(CLOCK_REALTIME, &timer_data->sigev, &timer_data->tid)==-1)
    {
        printf("init_timer: не могу создать таймер! \n");
        perror("timer_create");
        return -1;
    }
    
    return 0;       
    

    }

    int set_timer(timer_data_t *timer_data, UNS32 timeSec, UNS64 timeNsec)
    {
    timer_data->ival.it_value.tv_sec=timeSec;
    timer_data->ival.it_value.tv_nsec =timeNsec;
    timer_data->ival.it_interval.tv_sec=0;
    timer_data->ival.it_interval.tv_nsec=0;

    if(timer_settime(timer_data->tid, 0, &timer_data->ival, NULL) == -1)
    {
        perror("timer_settime");
        return -1;
    }
    
    return 0;
    

    }

    So, by calling init_timer, I'm just changing the processor for a specific signal, because it can only be one?



  • I don't understand your question.

    Do I understand correctly that the signal will reach all the signal processors?

    What do you mean, "to all"? Always. Gets to the signal processor, it's processed and it's done! One signal can't reach two processors. The signal manual says that if the signal is expected by several processors, who will receive it is the result.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2