MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / init_timer

Function init_timer

timer.c:117–206  ·  view source on GitHub ↗

ret 0 on success, <0 on error*/

Source from the content-addressed store, hash-verified

115
116/* ret 0 on success, <0 on error*/
117int init_timer(void)
118{
119 int optval;
120
121 jiffies = shm_malloc(sizeof(unsigned int));
122 ujiffies = shm_malloc(sizeof(utime_t));
123 ijiffies = shm_malloc(sizeof(utime_t));
124 ijiffies_drift = shm_malloc(sizeof(utime_t));
125 ijiffies_drift_base = shm_malloc(sizeof(utime_t));
126
127 if (jiffies==0 || ujiffies==0 || ijiffies==0 ||
128 ijiffies_drift==0 || ijiffies_drift_base==0){
129 LM_CRIT("could not init jiffies\n");
130 return E_OUT_OF_MEM;
131 }
132
133 if (UTIMER_TICK>TIMER_TICK*1000000) {
134 LM_CRIT("UTIMER > TIMER!!\n");
135 return E_CFG;
136 }
137
138 if ( ((TIMER_TICK*1000000) % UTIMER_TICK)!=0 ) {
139 LM_CRIT("TIMER must be multiple of UTIMER!!\n");
140 return E_CFG;
141 }
142
143 *jiffies=0;
144 *ujiffies=0;
145 *ijiffies=0;
146 *ijiffies_drift=0;
147 *ijiffies_drift_base=0;
148
149 /* create the pipe for dispatching the timer jobs */
150 if ( pipe(timer_pipe)!=0 ) {
151 LM_ERR("failed to create time pipe (%s)!\n",strerror(errno));
152 return E_UNSPEC;
153 }
154 /* make reading fd non-blocking */
155 optval=fcntl(timer_pipe[0], F_GETFL);
156 if (optval==-1){
157 LM_ERR("fcntl failed: (%d) %s\n", errno, strerror(errno));
158 return E_UNSPEC;
159 }
160 if (fcntl(timer_pipe[0],F_SETFL,optval|O_NONBLOCK)==-1){
161 LM_ERR("set non-blocking failed: (%d) %s\n",
162 errno, strerror(errno));
163 return E_UNSPEC;
164 }
165 /* make visible the "read" part of the pipe */
166 timer_fd_out = timer_pipe[0];
167
168 if (timer_auto_scaling_profile) {
169 s_profile = get_scaling_profile(timer_auto_scaling_profile);
170 if ( s_profile==NULL) {
171 LM_ERR("undefined auto-scaling profile <%s> for timers\n",
172 timer_auto_scaling_profile);
173 return E_UNSPEC;
174 }

Callers

nothing calls this directly

Calls 3

shm_mallocFunction · 0.85
get_scaling_profileFunction · 0.85
lock_initFunction · 0.85

Tested by

no test coverage detected