Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00038 #include "timer_proc.h"
00039 #include "cfg/cfg_struct.h"
00040 #include "pt.h"
00041 #include "ut.h"
00042 #include "mem/shm_mem.h"
00043
00044 #include <unistd.h>
00045
00046
00052 int register_basic_timers(int timers)
00053 {
00054 if(register_procs(timers)<0)
00055 return -1;
00056 cfg_register_child(timers);
00057 return 0;
00058 }
00059
00077 int fork_basic_timer(int child_id, char* desc, int make_sock,
00078 timer_function* f, void* param, int interval)
00079 {
00080 int pid;
00081
00082 pid=fork_process(child_id, desc, make_sock);
00083 if (pid<0) return -1;
00084 if (pid==0){
00085
00086 if (cfg_child_init()) return -1;
00087 for(;;){
00088 sleep(interval);
00089 cfg_update();
00090 f(get_ticks(), param);
00091
00092 }
00093 }
00094
00095 return pid;
00096 }
00097
00115 int fork_basic_utimer(int child_id, char* desc, int make_sock,
00116 utimer_function* f, void* param, int uinterval)
00117 {
00118 int pid;
00119 ticks_t ts;
00120
00121 pid=fork_process(child_id, desc, make_sock);
00122 if (pid<0) return -1;
00123 if (pid==0){
00124
00125 if (cfg_child_init()) return -1;
00126 for(;;){
00127 sleep_us(uinterval);
00128 cfg_update();
00129 ts = get_ticks_raw();
00130 f(TICKS_TO_MS(ts), param);
00131 }
00132 }
00133
00134 return pid;
00135 }
00136
00137
00166 int fork_local_timer_process(int child_id, char* desc, int make_sock,
00167 struct local_timer** lt_h)
00168 {
00169 int pid;
00170 struct local_timer* lt;
00171
00172 lt=shm_malloc(sizeof(*lt));
00173 if (lt==0) goto error;
00174 if (init_local_timer(lt, get_ticks_raw())<0) goto error;
00175 pid=fork_process(child_id, desc, make_sock);
00176 if (pid<0) goto error;
00177 *lt_h=lt;
00178 return pid;
00179 error:
00180 if (lt) shm_free(lt);
00181 return -1;
00182 }
00183
00189 int register_sync_timers(int timers)
00190 {
00191 if(register_procs(timers)<0)
00192 return -1;
00193 cfg_register_child(timers);
00194 return 0;
00195 }
00196
00214 int fork_sync_timer(int child_id, char* desc, int make_sock,
00215 timer_function* f, void* param, int interval)
00216 {
00217 int pid;
00218 ticks_t ts1 = 0;
00219 ticks_t ts2 = 0;
00220
00221 pid=fork_process(child_id, desc, make_sock);
00222 if (pid<0) return -1;
00223 if (pid==0){
00224
00225 ts2 = interval;
00226 if (cfg_child_init()) return -1;
00227 for(;;){
00228 if(ts2>0) sleep(ts2);
00229 else sleep(1);
00230 ts1 = get_ticks();
00231 cfg_update();
00232 f(get_ticks(), param);
00233
00234 ts2 = interval - get_ticks() + ts1;
00235 }
00236 }
00237
00238 return pid;
00239 }
00240
00241
00259 int fork_sync_utimer(int child_id, char* desc, int make_sock,
00260 utimer_function* f, void* param, int uinterval)
00261 {
00262 int pid;
00263 ticks_t ts1 = 0;
00264 ticks_t ts2 = 0;
00265
00266 pid=fork_process(child_id, desc, make_sock);
00267 if (pid<0) return -1;
00268 if (pid==0){
00269
00270 ts2 = uinterval;
00271 if (cfg_child_init()) return -1;
00272 for(;;){
00273 if(ts2>0) sleep_us(uinterval);
00274 else sleep_us(1);
00275 ts1 = get_ticks_raw();
00276 cfg_update();
00277 f(TICKS_TO_MS(ts1), param);
00278 ts2 = uinterval - get_ticks_raw() + ts1;
00279 }
00280 }
00281
00282 return pid;
00283 }
00284
00285
00286