Asterisk - The Open Source Telephony Project  21.4.1
Data Structures | Macros | Enumerations | Functions | Variables
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)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static int check_timer (struct pthread_timer *timer)
 
static void * do_timing (void *arg)
 
static int init_timing_thread (void)
 
static int load_module (void)
 
static int pthread_timer_ack (void *data, unsigned int quantity)
 
static void pthread_timer_close (void *data)
 
static int pthread_timer_cmp (void *obj, void *arg, int flags)
 
static void pthread_timer_destructor (void *obj)
 
static int pthread_timer_disable_continuous (void *data)
 
static int pthread_timer_enable_continuous (void *data)
 
static int pthread_timer_fd (void *data)
 
static enum ast_timer_event pthread_timer_get_event (void *data)
 
static unsigned int pthread_timer_get_max_rate (void *data)
 
static int pthread_timer_hash (const void *obj, const int flags)
 
static void * pthread_timer_open (void)
 
static int pthread_timer_set_rate (void *data, 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 = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_EXTENDED, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_TIMING, }
 
static const 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.
 

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.

Function Documentation

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 286 of file res_timing_pthread.c.

References ast_tvdiff_ms(), ast_tvnow(), and pthread_timer::interval.

287 {
288  struct timeval now;
289 
290  if (timer->state == TIMER_STATE_IDLE) {
291  return 0;
292  }
293 
294  now = ast_tvnow();
295 
296  if (timer->tick_count < (ast_tvdiff_ms(now, timer->start) / timer->interval)) {
297  timer->tick_count++;
298  if (!timer->tick_count) {
299  /* Handle overflow. */
300  timer->start = now;
301  }
302  return 1;
303  }
304 
305  return 0;
306 }
unsigned int interval
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:159
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
Definition: time.h:107
static int pthread_timer_cmp ( void *  obj,
void *  arg,
int  flags 
)
static
Note
only PIPE_READ is guaranteed valid

Definition at line 275 of file res_timing_pthread.c.

References CMP_MATCH, and CMP_STOP.

276 {
277  struct pthread_timer *timer1 = obj, *timer2 = arg;
278 
279  return (timer1->pipe[PIPE_READ] == timer2->pipe[PIPE_READ]) ? CMP_MATCH | CMP_STOP : 0;
280 }
static int pthread_timer_hash ( const void *  obj,
const int  flags 
)
static
Note
only PIPE_READ is guaranteed valid

Definition at line 265 of file res_timing_pthread.c.

266 {
267  const struct pthread_timer *timer = obj;
268 
269  return timer->pipe[PIPE_READ];
270 }