Wed Jan 8 2020 09:50:19

Asterisk developer's documentation


res_timing_pthread.c File Reference

pthread timing interface More...

#include "asterisk.h"
#include <stdbool.h>
#include <math.h>
#include <unistd.h>
#include <fcntl.h>
#include "asterisk/module.h"
#include "asterisk/timing.h"
#include "asterisk/utils.h"
#include "asterisk/astobj2.h"
#include "asterisk/time.h"
#include "asterisk/lock.h"

Go to the source code of this file.

Data Structures

struct  pthread_timer
 

Macros

#define MAX_RATE   100
 
#define PTHREAD_TIMER_BUCKETS   563
 

Enumerations

enum  { PIPE_READ = 0, PIPE_WRITE = 1 }
 
enum  pthread_timer_state { TIMER_STATE_IDLE, TIMER_STATE_TICKING }
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
static void ack_ticks (struct pthread_timer *timer, unsigned int num)
 
 ASTERISK_FILE_VERSION (__FILE__,"$Revision: 386109 $")
 
static int check_timer (struct pthread_timer *timer)
 
static void * do_timing (void *arg)
 
static struct pthread_timerfind_timer (int handle, int unlinkobj)
 
static int init_timing_thread (void)
 
static int load_module (void)
 
static int pthread_timer_ack (int handle, unsigned int quantity)
 
static void pthread_timer_close (int handle)
 
static int pthread_timer_cmp (void *obj, void *arg, int flags)
 
static void pthread_timer_destructor (void *obj)
 
static int pthread_timer_disable_continuous (int handle)
 
static int pthread_timer_enable_continuous (int handle)
 
static enum ast_timer_event pthread_timer_get_event (int handle)
 
static unsigned int pthread_timer_get_max_rate (int handle)
 
static int pthread_timer_hash (const void *obj, const int flags)
 
static int pthread_timer_open (void)
 
static int pthread_timer_set_rate (int handle, unsigned int rate)
 
static int run_timer (void *obj, void *arg, int flags)
 
static void signal_pipe (struct pthread_timer *timer)
 
static int unload_module (void)
 
static void unsignal_pipe (struct pthread_timer *timer)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "pthread Timing Interface" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_TIMING, }
 
static struct ast_module_infoast_module_info = &__mod_info
 
static struct ao2_containerpthread_timers
 
static struct ast_timing_interface pthread_timing
 
static void * timing_funcs_handle
 
struct {
   ast_cond_t   cond
 
   ast_mutex_t   lock
 
   unsigned int   stop:1
 
   pthread_t   thread
 
timing_thread
 Data for the timing thread. More...
 

Detailed Description

pthread timing interface

Author
Russell Bryant russe.nosp@m.ll@d.nosp@m.igium.nosp@m..com

Definition in file res_timing_pthread.c.

Macro Definition Documentation

#define MAX_RATE   100

Definition at line 71 of file res_timing_pthread.c.

Referenced by pthread_timer_get_max_rate(), and pthread_timer_set_rate().

#define PTHREAD_TIMER_BUCKETS   563

Definition at line 74 of file res_timing_pthread.c.

Referenced by load_module().

Enumeration Type Documentation

anonymous enum
Enumerator
PIPE_READ 
PIPE_WRITE 

Definition at line 76 of file res_timing_pthread.c.

76  {
77  PIPE_READ = 0,
78  PIPE_WRITE = 1
79 };
Enumerator
TIMER_STATE_IDLE 
TIMER_STATE_TICKING 

Definition at line 81 of file res_timing_pthread.c.

Function Documentation

static void __reg_module ( void  )
static

Definition at line 536 of file res_timing_pthread.c.

static void __unreg_module ( void  )
static

Definition at line 536 of file res_timing_pthread.c.

static void ack_ticks ( struct pthread_timer timer,
unsigned int  num 
)
static

Definition at line 374 of file res_timing_pthread.c.

References ast_assert, pthread_timer::continuous, pthread_timer::pending_ticks, and unsignal_pipe().

Referenced by pthread_timer_ack().

375 {
376  int pending_ticks = timer->pending_ticks;
377 
378  ast_assert(quantity);
379 
380  if (quantity > pending_ticks) {
381  quantity = pending_ticks;
382  }
383 
384  if (!quantity) {
385  return;
386  }
387 
388  timer->pending_ticks -= quantity;
389 
390  if ((0 == timer->pending_ticks) && !timer->continuous) {
391  unsignal_pipe(timer);
392  }
393 }
unsigned int pending_ticks
#define ast_assert(a)
Definition: utils.h:738
static void unsignal_pipe(struct pthread_timer *timer)
ASTERISK_FILE_VERSION ( __FILE__  ,
"$Revision: 386109 $"   
)
static int check_timer ( struct pthread_timer timer)
static
Return values
0no timer tick needed
non-zerowrite to the timing pipe needed

Definition at line 348 of file res_timing_pthread.c.

References ast_tvdiff_ms(), ast_tvnow(), pthread_timer::interval, pthread_timer::start, pthread_timer::state, pthread_timer::tick_count, and TIMER_STATE_IDLE.

Referenced by run_timer().

349 {
350  struct timeval now;
351 
352  if (timer->state == TIMER_STATE_IDLE) {
353  return 0;
354  }
355 
356  now = ast_tvnow();
357 
358  if (timer->tick_count < (ast_tvdiff_ms(now, timer->start) / timer->interval)) {
359  timer->tick_count++;
360  if (!timer->tick_count) {
361  /* Handle overflow. */
362  timer->start = now;
363  }
364  return 1;
365  }
366 
367  return 0;
368 }
struct timeval start
unsigned int tick_count
unsigned int interval
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:142
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
Definition: time.h:90
enum pthread_timer_state state
static void* do_timing ( void *  arg)
static

Definition at line 457 of file res_timing_pthread.c.

References ao2_callback, ao2_container_count(), ast_cond_timedwait, ast_cond_wait, ast_mutex_lock, ast_mutex_unlock, ast_tv(), ast_tvadd(), ast_tvnow(), OBJ_NODATA, run_timer(), and timing_thread.

Referenced by init_timing_thread().

458 {
459  struct timeval next_wakeup = ast_tvnow();
460 
461  while (!timing_thread.stop) {
462  struct timespec ts = { 0, };
463 
465 
466  next_wakeup = ast_tvadd(next_wakeup, ast_tv(0, 5000));
467 
468  ts.tv_sec = next_wakeup.tv_sec;
469  ts.tv_nsec = next_wakeup.tv_usec * 1000;
470 
472  if (!timing_thread.stop) {
475  } else {
477  }
478  }
480  }
481 
482  return NULL;
483 }
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
Definition: astobj2.c:470
static struct ao2_container * pthread_timers
#define ao2_callback(c, flags, cb_fn, arg)
Definition: astobj2.h:910
#define ast_cond_wait(cond, mutex)
Definition: lock.h:171
static struct @352 timing_thread
Data for the timing thread.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:142
#define ast_mutex_lock(a)
Definition: lock.h:155
static int run_timer(void *obj, void *arg, int flags)
struct timeval ast_tvadd(struct timeval a, struct timeval b)
Returns the sum of two timevals a + b.
Definition: utils.c:1587
struct timeval ast_tv(ast_time_t sec, ast_suseconds_t usec)
Returns a timeval from sec, usec.
Definition: time.h:179
#define ast_cond_timedwait(cond, mutex, time)
Definition: lock.h:172
#define ast_mutex_unlock(a)
Definition: lock.h:156
static struct pthread_timer * find_timer ( int  handle,
int  unlinkobj 
)
static

Definition at line 289 of file res_timing_pthread.c.

References ao2_find, ast_assert, OBJ_POINTER, OBJ_UNLINK, pthread_timer::pipe, PIPE_READ, and timer.

Referenced by pthread_timer_ack(), pthread_timer_close(), pthread_timer_disable_continuous(), pthread_timer_enable_continuous(), pthread_timer_get_event(), and pthread_timer_set_rate().

290 {
291  struct pthread_timer *timer;
292  struct pthread_timer tmp_timer;
293  int flags = OBJ_POINTER;
294 
295  tmp_timer.pipe[PIPE_READ] = handle;
296 
297  if (unlinkobj) {
298  flags |= OBJ_UNLINK;
299  }
300 
301  if (!(timer = ao2_find(pthread_timers, &tmp_timer, flags))) {
302  ast_assert(timer != NULL);
303  return NULL;
304  }
305 
306  return timer;
307 }
static struct ao2_container * pthread_timers
#define ast_assert(a)
Definition: utils.h:738
#define ao2_find(arg1, arg2, arg3)
Definition: astobj2.h:964
static struct ast_timer * timer
Definition: chan_iax2.c:313
static int init_timing_thread ( void  )
static

Definition at line 485 of file res_timing_pthread.c.

References ast_cond_init, ast_log(), ast_mutex_init, ast_pthread_create_background, do_timing(), LOG_ERROR, and timing_thread.

Referenced by load_module().

486 {
488  ast_cond_init(&timing_thread.cond, NULL);
489 
490  if (ast_pthread_create_background(&timing_thread.thread, NULL, do_timing, NULL)) {
491  ast_log(LOG_ERROR, "Unable to start timing thread.\n");
492  return -1;
493  }
494 
495  return 0;
496 }
#define ast_cond_init(cond, attr)
Definition: lock.h:167
static struct @352 timing_thread
Data for the timing thread.
#define ast_pthread_create_background(a, b, c, d)
Definition: utils.h:426
static void * do_timing(void *arg)
#define LOG_ERROR
Definition: logger.h:155
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define ast_mutex_init(pmutex)
Definition: lock.h:152
static int load_module ( void  )
static

Definition at line 498 of file res_timing_pthread.c.

References ao2_container_alloc, ao2_ref, AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, ast_register_timing_interface, init_timing_thread(), PTHREAD_TIMER_BUCKETS, pthread_timer_cmp(), pthread_timer_hash(), and timing_funcs_handle.

499 {
503  }
504 
505  if (init_timing_thread()) {
506  ao2_ref(pthread_timers, -1);
507  pthread_timers = NULL;
509  }
510 
513 }
static struct ast_timing_interface pthread_timing
static struct ao2_container * pthread_timers
#define PTHREAD_TIMER_BUCKETS
#define ao2_ref(o, delta)
Definition: astobj2.h:472
static int pthread_timer_cmp(void *obj, void *arg, int flags)
#define ao2_container_alloc(arg1, arg2, arg3)
Definition: astobj2.h:734
static void * timing_funcs_handle
#define ast_register_timing_interface(i)
Register a set of timing functions.
Definition: timing.h:94
static int init_timing_thread(void)
static int pthread_timer_hash(const void *obj, const int flags)
static int pthread_timer_ack ( int  handle,
unsigned int  quantity 
)
static

Definition at line 203 of file res_timing_pthread.c.

References ack_ticks(), ao2_lock, ao2_ref, ao2_unlock, ast_assert, find_timer(), and timer.

204 {
205  struct pthread_timer *timer;
206 
207  ast_assert(quantity > 0);
208 
209  if (!(timer = find_timer(handle, 0))) {
210  return -1;
211  }
212 
213  ao2_lock(timer);
214  ack_ticks(timer, quantity);
215  ao2_unlock(timer);
216 
217  ao2_ref(timer, -1);
218 
219  return 0;
220 }
static struct pthread_timer * find_timer(int handle, int unlinkobj)
static void ack_ticks(struct pthread_timer *timer, unsigned int num)
#define ast_assert(a)
Definition: utils.h:738
#define ao2_unlock(a)
Definition: astobj2.h:497
#define ao2_ref(o, delta)
Definition: astobj2.h:472
#define ao2_lock(a)
Definition: astobj2.h:488
static struct ast_timer * timer
Definition: chan_iax2.c:313
static void pthread_timer_close ( int  handle)
static

Definition at line 156 of file res_timing_pthread.c.

References ao2_ref, find_timer(), and timer.

157 {
158  struct pthread_timer *timer;
159 
160  if (!(timer = find_timer(handle, 1))) {
161  return;
162  }
163 
164  ao2_ref(timer, -1);
165 }
static struct pthread_timer * find_timer(int handle, int unlinkobj)
#define ao2_ref(o, delta)
Definition: astobj2.h:472
static struct ast_timer * timer
Definition: chan_iax2.c:313
static int pthread_timer_cmp ( void *  obj,
void *  arg,
int  flags 
)
static
Note
only PIPE_READ is guaranteed valid

Definition at line 337 of file res_timing_pthread.c.

References CMP_MATCH, CMP_STOP, pthread_timer::pipe, and PIPE_READ.

Referenced by load_module().

338 {
339  struct pthread_timer *timer1 = obj, *timer2 = arg;
340 
341  return (timer1->pipe[PIPE_READ] == timer2->pipe[PIPE_READ]) ? CMP_MATCH | CMP_STOP : 0;
342 }
static void pthread_timer_destructor ( void *  obj)
static

Definition at line 309 of file res_timing_pthread.c.

References pthread_timer::pipe, PIPE_READ, PIPE_WRITE, and timer.

Referenced by pthread_timer_open().

310 {
311  struct pthread_timer *timer = obj;
312 
313  if (timer->pipe[PIPE_READ] > -1) {
314  close(timer->pipe[PIPE_READ]);
315  timer->pipe[PIPE_READ] = -1;
316  }
317 
318  if (timer->pipe[PIPE_WRITE] > -1) {
319  close(timer->pipe[PIPE_WRITE]);
320  timer->pipe[PIPE_WRITE] = -1;
321  }
322 }
static struct ast_timer * timer
Definition: chan_iax2.c:313
static int pthread_timer_disable_continuous ( int  handle)
static

Definition at line 243 of file res_timing_pthread.c.

References ao2_lock, ao2_ref, ao2_unlock, pthread_timer::continuous, errno, find_timer(), timer, and unsignal_pipe().

244 {
245  struct pthread_timer *timer;
246 
247  if (!(timer = find_timer(handle, 0))) {
248  errno = EINVAL;
249  return -1;
250  }
251 
252  ao2_lock(timer);
253  if (timer->continuous) {
254  timer->continuous = false;
255  unsignal_pipe(timer);
256  }
257  ao2_unlock(timer);
258 
259  ao2_ref(timer, -1);
260 
261  return 0;
262 }
static struct pthread_timer * find_timer(int handle, int unlinkobj)
#define ao2_unlock(a)
Definition: astobj2.h:497
#define ao2_ref(o, delta)
Definition: astobj2.h:472
#define ao2_lock(a)
Definition: astobj2.h:488
int errno
static void unsignal_pipe(struct pthread_timer *timer)
static struct ast_timer * timer
Definition: chan_iax2.c:313
static int pthread_timer_enable_continuous ( int  handle)
static

Definition at line 222 of file res_timing_pthread.c.

References ao2_lock, ao2_ref, ao2_unlock, pthread_timer::continuous, errno, find_timer(), signal_pipe(), and timer.

223 {
224  struct pthread_timer *timer;
225 
226  if (!(timer = find_timer(handle, 0))) {
227  errno = EINVAL;
228  return -1;
229  }
230 
231  ao2_lock(timer);
232  if (!timer->continuous) {
233  timer->continuous = true;
234  signal_pipe(timer);
235  }
236  ao2_unlock(timer);
237 
238  ao2_ref(timer, -1);
239 
240  return 0;
241 }
static struct pthread_timer * find_timer(int handle, int unlinkobj)
#define ao2_unlock(a)
Definition: astobj2.h:497
static void signal_pipe(struct pthread_timer *timer)
#define ao2_ref(o, delta)
Definition: astobj2.h:472
#define ao2_lock(a)
Definition: astobj2.h:488
int errno
static struct ast_timer * timer
Definition: chan_iax2.c:313
static enum ast_timer_event pthread_timer_get_event ( int  handle)
static

Definition at line 264 of file res_timing_pthread.c.

References ao2_lock, ao2_ref, ao2_unlock, AST_TIMING_EVENT_CONTINUOUS, AST_TIMING_EVENT_EXPIRED, pthread_timer::continuous, find_timer(), and timer.

265 {
266  struct pthread_timer *timer;
268 
269  if (!(timer = find_timer(handle, 0))) {
270  return res;
271  }
272 
273  ao2_lock(timer);
274  if (timer->continuous) {
276  }
277  ao2_unlock(timer);
278 
279  ao2_ref(timer, -1);
280 
281  return res;
282 }
static struct pthread_timer * find_timer(int handle, int unlinkobj)
ast_timer_event
Definition: timing.h:57
#define ao2_unlock(a)
Definition: astobj2.h:497
#define ao2_ref(o, delta)
Definition: astobj2.h:472
#define ao2_lock(a)
Definition: astobj2.h:488
static struct ast_timer * timer
Definition: chan_iax2.c:313
static unsigned int pthread_timer_get_max_rate ( int  handle)
static

Definition at line 284 of file res_timing_pthread.c.

References MAX_RATE.

285 {
286  return MAX_RATE;
287 }
#define MAX_RATE
static int pthread_timer_hash ( const void *  obj,
const int  flags 
)
static
Note
only PIPE_READ is guaranteed valid

Definition at line 327 of file res_timing_pthread.c.

References pthread_timer::pipe, PIPE_READ, and timer.

Referenced by load_module().

328 {
329  const struct pthread_timer *timer = obj;
330 
331  return timer->pipe[PIPE_READ];
332 }
static struct ast_timer * timer
Definition: chan_iax2.c:313
static int pthread_timer_open ( void  )
static

Definition at line 115 of file res_timing_pthread.c.

References ao2_alloc, ao2_container_count(), ao2_link, ao2_lock, ao2_ref, ao2_unlock, ARRAY_LEN, ast_cond_signal, ast_mutex_lock, ast_mutex_unlock, errno, pthread_timer::pipe, PIPE_READ, PIPE_WRITE, pthread_timer_destructor(), pthread_timer::state, timer, TIMER_STATE_IDLE, and timing_thread.

116 {
117  struct pthread_timer *timer;
118  int fd;
119  int i;
120 
121  if (!(timer = ao2_alloc(sizeof(*timer), pthread_timer_destructor))) {
122  errno = ENOMEM;
123  return -1;
124  }
125 
126  timer->pipe[PIPE_READ] = timer->pipe[PIPE_WRITE] = -1;
127  timer->state = TIMER_STATE_IDLE;
128 
129  if (pipe(timer->pipe)) {
130  ao2_ref(timer, -1);
131  return -1;
132  }
133 
134  for (i = 0; i < ARRAY_LEN(timer->pipe); ++i) {
135  int flags = fcntl(timer->pipe[i], F_GETFL);
136  flags |= O_NONBLOCK;
137  fcntl(timer->pipe[i], F_SETFL, flags);
138  }
139 
145  }
146  ao2_link(pthread_timers, timer);
148 
149  fd = timer->pipe[PIPE_READ];
150 
151  ao2_ref(timer, -1);
152 
153  return fd;
154 }
#define ao2_link(arg1, arg2)
Definition: astobj2.h:785
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
Definition: astobj2.c:470
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
static struct ao2_container * pthread_timers
static void pthread_timer_destructor(void *obj)
static struct @352 timing_thread
Data for the timing thread.
#define ast_mutex_lock(a)
Definition: lock.h:155
#define ao2_unlock(a)
Definition: astobj2.h:497
#define ast_cond_signal(cond)
Definition: lock.h:169
#define ao2_ref(o, delta)
Definition: astobj2.h:472
#define ao2_lock(a)
Definition: astobj2.h:488
enum pthread_timer_state state
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:430
int errno
static struct ast_timer * timer
Definition: chan_iax2.c:313
#define ast_mutex_unlock(a)
Definition: lock.h:156
static int pthread_timer_set_rate ( int  handle,
unsigned int  rate 
)
static

Definition at line 167 of file res_timing_pthread.c.

References ao2_lock, ao2_ref, ao2_unlock, ast_log(), ast_tv(), ast_tvnow(), errno, find_timer(), pthread_timer::interval, LOG_ERROR, MAX_RATE, pthread_timer::rate, roundf(), pthread_timer::start, pthread_timer::state, pthread_timer::tick_count, timer, TIMER_STATE_IDLE, and TIMER_STATE_TICKING.

168 {
169  struct pthread_timer *timer;
170 
171  if (!(timer = find_timer(handle, 0))) {
172  errno = EINVAL;
173  return -1;
174  }
175 
176  if (rate > MAX_RATE) {
177  ast_log(LOG_ERROR, "res_timing_pthread only supports timers at a "
178  "max rate of %d / sec\n", MAX_RATE);
179  errno = EINVAL;
180  return -1;
181  }
182 
183  ao2_lock(timer);
184 
185  if ((timer->rate = rate)) {
186  timer->interval = roundf(1000.0 / ((float) rate));
187  timer->start = ast_tvnow();
188  timer->state = TIMER_STATE_TICKING;
189  } else {
190  timer->interval = 0;
191  timer->start = ast_tv(0, 0);
192  timer->state = TIMER_STATE_IDLE;
193  }
194  timer->tick_count = 0;
195 
196  ao2_unlock(timer);
197 
198  ao2_ref(timer, -1);
199 
200  return 0;
201 }
static struct pthread_timer * find_timer(int handle, int unlinkobj)
unsigned int rate
struct timeval start
unsigned int tick_count
unsigned int interval
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:142
#define ao2_unlock(a)
Definition: astobj2.h:497
float roundf(float x)
#define ao2_ref(o, delta)
Definition: astobj2.h:472
#define ao2_lock(a)
Definition: astobj2.h:488
enum pthread_timer_state state
#define LOG_ERROR
Definition: logger.h:155
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
int errno
#define MAX_RATE
struct timeval ast_tv(ast_time_t sec, ast_suseconds_t usec)
Returns a timeval from sec, usec.
Definition: time.h:179
static struct ast_timer * timer
Definition: chan_iax2.c:313
static int run_timer ( void *  obj,
void *  arg,
int  flags 
)
static

Definition at line 439 of file res_timing_pthread.c.

References ao2_lock, ao2_unlock, check_timer(), pthread_timer::pending_ticks, signal_pipe(), pthread_timer::state, timer, and TIMER_STATE_IDLE.

Referenced by do_timing().

440 {
441  struct pthread_timer *timer = obj;
442 
443  if (timer->state == TIMER_STATE_IDLE) {
444  return 0;
445  }
446 
447  ao2_lock(timer);
448  if (check_timer(timer)) {
449  timer->pending_ticks++;
450  signal_pipe(timer);
451  }
452  ao2_unlock(timer);
453 
454  return 0;
455 }
static int check_timer(struct pthread_timer *timer)
unsigned int pending_ticks
#define ao2_unlock(a)
Definition: astobj2.h:497
static void signal_pipe(struct pthread_timer *timer)
#define ao2_lock(a)
Definition: astobj2.h:488
enum pthread_timer_state state
static struct ast_timer * timer
Definition: chan_iax2.c:313
static void signal_pipe ( struct pthread_timer timer)
static

Definition at line 399 of file res_timing_pthread.c.

References ast_log(), errno, LOG_ERROR, pthread_timer::pipe, pthread_timer::pipe_signaled, and PIPE_WRITE.

Referenced by pthread_timer_enable_continuous(), and run_timer().

400 {
401  ssize_t res;
402  unsigned char x = 42;
403 
404  if (timer->pipe_signaled) {
405  return;
406  }
407 
408  res = write(timer->pipe[PIPE_WRITE], &x, 1);
409  if (-1 == res) {
410  ast_log(LOG_ERROR, "Error writing to timing pipe: %s\n",
411  strerror(errno));
412  } else {
413  timer->pipe_signaled = true;
414  }
415 }
#define LOG_ERROR
Definition: logger.h:155
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
int errno
static int unload_module ( void  )
static

Definition at line 515 of file res_timing_pthread.c.

References ao2_ref, ast_cond_signal, ast_mutex_lock, ast_mutex_unlock, ast_unregister_timing_interface(), timing_funcs_handle, and timing_thread.

516 {
517  int res;
518 
520  timing_thread.stop = 1;
523  pthread_join(timing_thread.thread, NULL);
524 
526  ao2_ref(pthread_timers, -1);
527  pthread_timers = NULL;
528  }
529 
530  return res;
531 }
static struct ao2_container * pthread_timers
int ast_unregister_timing_interface(void *handle)
Unregister a previously registered timing interface.
Definition: timing.c:105
static struct @352 timing_thread
Data for the timing thread.
#define ast_mutex_lock(a)
Definition: lock.h:155
#define ast_cond_signal(cond)
Definition: lock.h:169
#define ao2_ref(o, delta)
Definition: astobj2.h:472
static void * timing_funcs_handle
#define ast_mutex_unlock(a)
Definition: lock.h:156
static void unsignal_pipe ( struct pthread_timer timer)
static

Definition at line 421 of file res_timing_pthread.c.

References ast_log(), errno, LOG_ERROR, pthread_timer::pipe, PIPE_READ, and pthread_timer::pipe_signaled.

Referenced by ack_ticks(), and pthread_timer_disable_continuous().

422 {
423  ssize_t res;
424  unsigned long buffer;
425 
426  if (!timer->pipe_signaled) {
427  return;
428  }
429 
430  res = read(timer->pipe[PIPE_READ], &buffer, sizeof(buffer));
431  if (-1 == res) {
432  ast_log(LOG_ERROR, "Error reading from pipe: %s\n",
433  strerror(errno));
434  } else {
435  timer->pipe_signaled = false;
436  }
437 }
#define LOG_ERROR
Definition: logger.h:155
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
int errno

Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "pthread Timing Interface" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_TIMING, }
static

Definition at line 536 of file res_timing_pthread.c.

Definition at line 536 of file res_timing_pthread.c.

ast_cond_t cond

Definition at line 111 of file res_timing_pthread.c.

Definition at line 110 of file res_timing_pthread.c.

struct ao2_container* pthread_timers
static

Definition at line 73 of file res_timing_pthread.c.

struct ast_timing_interface pthread_timing
static

Definition at line 57 of file res_timing_pthread.c.

unsigned int stop

Definition at line 112 of file res_timing_pthread.c.

pthread_t thread

Definition at line 109 of file res_timing_pthread.c.

void* timing_funcs_handle
static

Definition at line 46 of file res_timing_pthread.c.

Referenced by load_module(), and unload_module().

struct { ... } timing_thread

Data for the timing thread.

Referenced by do_timing(), init_timing_thread(), pthread_timer_open(), and unload_module().