core: allow a worker id in timer routines
authorlazedo <luis.azedo@factorlusitano.com>
Tue, 5 Mar 2019 09:59:04 +0000 (09:59 +0000)
committerHenning Westerholt <henningw@users.noreply.github.com>
Sat, 9 Mar 2019 11:52:43 +0000 (12:52 +0100)
src/core/timer.h
src/core/timer_proc.c
src/core/timer_proc.h

index 3b1669a..2c7f330 100644 (file)
@@ -62,6 +62,7 @@ extern pid_t slow_timer_pid;
 
 /* deprecated, old, kept for compatibility */
 typedef void (timer_function)(unsigned int ticks, void* param);
+typedef void (timer_function_w)(unsigned int ticks, int worker, void* param);
 /* deprecated, old, kept for compatibility
        get_ticks()*TIMER_TICK used to be the time in s
        for new code, use get_ticks_raw() and one of the macros defined in
@@ -70,6 +71,7 @@ typedef void (timer_function)(unsigned int ticks, void* param);
 
 /*function prototype to execute on mili-second based basic timers */
 typedef void (utimer_function)(unsigned int uticks, void* param);
+typedef void (utimer_function_w)(unsigned int uticks, int worker, void* param);
 
 struct timer_ln; /* forward decl */
 /* new
index 20c50e0..d153c63 100644 (file)
@@ -84,6 +84,27 @@ int fork_basic_timer(int child_id, char* desc, int make_sock,
        return pid;
 }
 
+int fork_basic_timer_w(int child_id, char* desc, int make_sock,
+                                               timer_function_w* f, int worker, void* param, int interval)
+{
+       int pid;
+
+       pid=fork_process(child_id, desc, make_sock);
+       if (pid<0) return -1;
+       if (pid==0){
+               /* child */
+               if (cfg_child_init()) return -1;
+               for(;;){
+                       sleep(interval);
+                       cfg_update();
+                       f(get_ticks(), worker, param); /* ticks in s for compatibility with old
+                                                                       * timers */
+               }
+       }
+       /* parent */
+       return pid;
+}
+
 /**
  * \brief Forks a separate simple microsecond-sleep() periodic timer
  *
@@ -123,6 +144,28 @@ int fork_basic_utimer(int child_id, char* desc, int make_sock,
        return pid;
 }
 
+int fork_basic_utimer_w(int child_id, char* desc, int make_sock,
+                                               utimer_function_w* f, int worker, void* param, int uinterval)
+{
+       int pid;
+       ticks_t ts;
+
+       pid=fork_process(child_id, desc, make_sock);
+       if (pid<0) return -1;
+       if (pid==0){
+               /* child */
+               if (cfg_child_init()) return -1;
+               for(;;){
+                       sleep_us(uinterval);
+                       cfg_update();
+                       ts = get_ticks_raw();
+                       f(TICKS_TO_MS(ts), worker, param); /* ticks in mili-seconds */
+               }
+       }
+       /* parent */
+       return pid;
+}
+
 
 /**
  * \brief Forks a timer process based on the local timer
index baaf366..8c4c6fa 100644 (file)
@@ -58,6 +58,8 @@ int register_basic_timers(int timers);
  */
 int fork_basic_timer(int child_id, char* desc, int make_sock,
                                                timer_function* f, void* param, int interval);
+int fork_basic_timer_w(int child_id, char* desc, int make_sock,
+                                               timer_function_w* f, int worker, void* param, int interval);
 
 #define fork_dummy_timer fork_basic_timer
 
@@ -80,6 +82,8 @@ int fork_basic_timer(int child_id, char* desc, int make_sock,
  */
 int fork_basic_utimer(int child_id, char* desc, int make_sock,
                                                timer_function* f, void* param, int uinterval);
+int fork_basic_utimer_w(int child_id, char* desc, int make_sock,
+                                               timer_function_w* f, int worker, void* param, int uinterval);
 /**
  * \brief Forks a timer process based on the local timer
  *