rtimer: use timer worker id
authorlazedo <luis.azedo@factorlusitano.com>
Tue, 5 Mar 2019 10:29:02 +0000 (10:29 +0000)
committerHenning Westerholt <henningw@users.noreply.github.com>
Sat, 9 Mar 2019 11:52:43 +0000 (12:52 +0100)
src/modules/rtimer/rtimer_mod.c

index 018986b..4b39814 100644 (file)
@@ -74,8 +74,14 @@ static int child_init(int);
 
 int stm_t_param(modparam_t type, void* val);
 int stm_e_param(modparam_t type, void* val);
-void stm_timer_exec(unsigned int ticks, void *param);
+void stm_timer_exec(unsigned int ticks, int worker, void *param);
+void stm_main_timer_exec(unsigned int ticks, void *param);
+int stm_get_worker(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
 
+static pv_export_t rtimer_pvs[] = {
+       {{"rtimer_worker", (sizeof("rtimer_worker")-1)}, PVT_OTHER, stm_get_worker, 0,  0, 0, 0, 0},
+       { {0, 0}, 0, 0, 0, 0, 0, 0, 0 }
+};
 
 static param_export_t params[]={
        {"timer",             PARAM_STRING|USE_FUNC_PARAM, (void*)stm_t_param},
@@ -91,7 +97,7 @@ struct module_exports exports= {
        0,
        params,
        0,           /* exported RPC methods */
-       0,           /* exported pseudo-variables */
+       rtimer_pvs,  /* exported pseudo-variables */
        0,
        mod_init,    /* module initialization function */
        child_init,  /* per-child init function */
@@ -121,7 +127,7 @@ static int mod_init(void)
        {
                if(it->mode==0)
                {
-                       if(register_timer(stm_timer_exec, (void*)it, it->interval)<0)
+                       if(register_timer(stm_main_timer_exec, (void*)it, it->interval)<0)
                        {
                                LM_ERR("failed to register timer function\n");
                                return -1;
@@ -156,15 +162,15 @@ static int child_init(int rank)
                                 i, it->name.len, it->name.s);
                        if(it->flags & RTIMER_INTERVAL_USEC)
                        {
-                               if(fork_basic_utimer(PROC_TIMER, si_desc, 1 /*socks flag*/,
-                                                               stm_timer_exec, (void*)it, it->interval
+                               if(fork_basic_utimer_w(PROC_TIMER, si_desc, 1 /*socks flag*/,
+                                                               stm_timer_exec, i, (void*)it, it->interval
                                                                /*usec*/)<0) {
                                        LM_ERR("failed to start utimer routine as process\n");
                                        return -1; /* error */
                                }
                        } else {
-                               if(fork_basic_timer(PROC_TIMER, si_desc, 1 /*socks flag*/,
-                                                               stm_timer_exec, (void*)it, it->interval
+                               if(fork_basic_timer_w(PROC_TIMER, si_desc, 1 /*socks flag*/,
+                                                               stm_timer_exec, i, (void*)it, it->interval
                                                                /*sec*/)<0) {
                                        LM_ERR("failed to start timer routine as process\n");
                                        return -1; /* error */
@@ -177,13 +183,21 @@ static int child_init(int rank)
        return 0;
 }
 
-void stm_timer_exec(unsigned int ticks, void *param)
+int rt_worker = 0;
+
+void stm_main_timer_exec(unsigned int ticks, void *param)
+{
+       stm_timer_exec(ticks, 0, param);
+}
+
+void stm_timer_exec(unsigned int ticks, int worker, void *param)
 {
        stm_timer_t *it;
        stm_route_t *rt;
        sip_msg_t *fmsg;
        sr_kemi_eng_t *keng = NULL;
        str evname = str_init("rtimer");
+       rt_worker = worker;
 
        if(param==NULL)
                return;
@@ -382,3 +396,7 @@ int stm_e_param(modparam_t type, void *val)
        return 0;
 }
 
+int stm_get_worker(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
+{
+       return pv_get_sintval(msg, param, res, rt_worker);
+}