Asterisk - The Open Source Telephony Project  18.5.0
Data Structures | Macros | Functions | Variables
pjsip_scheduler.c File Reference

res_pjsip Scheduler More...

#include "asterisk.h"
#include "asterisk/res_pjsip.h"
#include "include/res_pjsip_private.h"
#include "asterisk/res_pjsip_cli.h"
#include "asterisk/taskprocessor.h"
#include <regex.h>
Include dependency graph for pjsip_scheduler.c:

Go to the source code of this file.

Data Structures

struct  ast_sip_sched_task
 

Macros

#define ID_LEN   13 /* task_deadbeef */
 
#define TASK_BUCKETS   53
 
#define TIME_FORMAT   "%a %T"
 

Functions

 AO2_STRING_FIELD_CMP_FN (ast_sip_sched_task, name)
 
 AO2_STRING_FIELD_HASH_FN (ast_sip_sched_task, name)
 
 AO2_STRING_FIELD_SORT_FN (ast_sip_sched_task, name)
 
int ast_sip_destroy_scheduler (void)
 
int ast_sip_initialize_scheduler (void)
 Initialize scheduler. More...
 
int ast_sip_sched_is_task_running (struct ast_sip_sched_task *schtd)
 Checks if the task is currently running. More...
 
int ast_sip_sched_is_task_running_by_name (const char *name)
 Checks if the task is currently running. More...
 
int ast_sip_sched_task_cancel (struct ast_sip_sched_task *schtd)
 Cancels the next invocation of a task. More...
 
int ast_sip_sched_task_cancel_by_name (const char *name)
 Cancels the next invocation of a task by name. More...
 
int ast_sip_sched_task_get_name (struct ast_sip_sched_task *schtd, char *name, size_t maxlen)
 Gets the task name. More...
 
int ast_sip_sched_task_get_next_run (struct ast_sip_sched_task *schtd)
 Gets the number of milliseconds until the next invocation. More...
 
int ast_sip_sched_task_get_next_run_by_name (const char *name)
 Gets the number of milliseconds until the next invocation. More...
 
int ast_sip_sched_task_get_times (struct ast_sip_sched_task *schtd, struct timeval *queued, struct timeval *last_start, struct timeval *last_end)
 Gets the last start and end times of the task. More...
 
int ast_sip_sched_task_get_times2 (struct ast_sip_sched_task *schtd, struct timeval *queued, struct timeval *last_start, struct timeval *last_end, int *interval, int *time_left, struct timeval *next_start)
 Gets the queued, last start, last_end, time left, interval, next run. More...
 
int ast_sip_sched_task_get_times_by_name (const char *name, struct timeval *queued, struct timeval *last_start, struct timeval *last_end)
 Gets the last start and end times of the task by name. More...
 
int ast_sip_sched_task_get_times_by_name2 (const char *name, struct timeval *queued, struct timeval *last_start, struct timeval *last_end, int *interval, int *time_left, struct timeval *next_start)
 Gets the queued, last start, last_end, time left, interval, next run by task name. More...
 
struct ast_sip_sched_taskast_sip_schedule_task (struct ast_taskprocessor *serializer, int interval, ast_sip_task sip_task, const char *name, void *task_data, enum ast_sip_scheduler_task_flags flags)
 Schedule a task to run in the res_pjsip thread pool. More...
 
static char * cli_show_tasks (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static int push_to_serializer (const void *data)
 
static int run_task (void *data)
 
static void schtd_dtor (void *data)
 

Variables

static struct ast_cli_entry cli_commands []
 
static struct ast_sched_contextscheduler_context
 
static int task_count
 
static struct ao2_containertasks
 

Detailed Description

res_pjsip Scheduler

Author
George Joseph georg.nosp@m.e.jo.nosp@m.seph@.nosp@m.fair.nosp@m.view5.nosp@m..com

Definition in file pjsip_scheduler.c.

Macro Definition Documentation

◆ ID_LEN

#define ID_LEN   13 /* task_deadbeef */

Referenced by ast_sip_schedule_task().

◆ TASK_BUCKETS

#define TASK_BUCKETS   53

Definition at line 35 of file pjsip_scheduler.c.

Referenced by ast_sip_initialize_scheduler().

◆ TIME_FORMAT

#define TIME_FORMAT   "%a %T"

Definition at line 488 of file pjsip_scheduler.c.

Referenced by cli_show_tasks().

Function Documentation

◆ AO2_STRING_FIELD_CMP_FN()

AO2_STRING_FIELD_CMP_FN ( ast_sip_sched_task  ,
name   
)

◆ AO2_STRING_FIELD_HASH_FN()

AO2_STRING_FIELD_HASH_FN ( ast_sip_sched_task  ,
name   
)

◆ AO2_STRING_FIELD_SORT_FN()

AO2_STRING_FIELD_SORT_FN ( ast_sip_sched_task  ,
name   
)

◆ ast_sip_destroy_scheduler()

int ast_sip_destroy_scheduler ( void  )

Definition at line 642 of file pjsip_scheduler.c.

References ao2_cleanup, ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, ARRAY_LEN, ast_cli_unregister_multiple(), ast_sched_context_destroy(), ast_sip_sched_task_cancel(), and NULL.

Referenced by load_module(), and unload_module().

643 {
645 
646  if (scheduler_context) {
647  if (tasks) {
648  struct ao2_iterator iter;
649  struct ast_sip_sched_task *schtd;
650 
651  /* Cancel all scheduled tasks */
652  iter = ao2_iterator_init(tasks, 0);
653  while ((schtd = ao2_iterator_next(&iter))) {
655  ao2_ref(schtd, -1);
656  }
657  ao2_iterator_destroy(&iter);
658  }
659 
662  }
663 
665  tasks = NULL;
666 
667  return 0;
668 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
Definition: clicompat.c:30
int ast_sip_sched_task_cancel(struct ast_sip_sched_task *schtd)
Cancels the next invocation of a task.
static struct ast_sched_context * scheduler_context
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
#define NULL
Definition: resample.c:96
#define ao2_ref(o, delta)
Definition: astobj2.h:464
static struct ast_cli_entry cli_commands[]
#define ao2_iterator_next(iter)
Definition: astobj2.h:1933
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition: astobj2.h:1841
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
static struct ao2_container * tasks
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.
void ast_sched_context_destroy(struct ast_sched_context *c)
destroys a schedule context
Definition: sched.c:269

◆ ast_sip_initialize_scheduler()

int ast_sip_initialize_scheduler ( void  )

Initialize scheduler.

Since
13.9.0
Return values
-1failure
0success

Definition at line 614 of file pjsip_scheduler.c.

References AO2_ALLOC_OPT_LOCK_RWLOCK, ao2_container_alloc_hash, AO2_CONTAINER_ALLOC_OPT_DUPS_REJECT, ARRAY_LEN, ast_cli_register_multiple, ast_log, ast_sched_context_create(), ast_sched_context_destroy(), ast_sched_start_thread(), LOG_ERROR, and TASK_BUCKETS.

Referenced by load_module().

615 {
617  if (!scheduler_context) {
618  ast_log(LOG_ERROR, "Failed to create scheduler. Aborting load\n");
619  return -1;
620  }
621 
623  ast_log(LOG_ERROR, "Failed to start scheduler. Aborting load\n");
625  return -1;
626  }
627 
629  AO2_CONTAINER_ALLOC_OPT_DUPS_REJECT, TASK_BUCKETS, ast_sip_sched_task_hash_fn,
630  ast_sip_sched_task_sort_fn, ast_sip_sched_task_cmp_fn);
631  if (!tasks) {
632  ast_log(LOG_ERROR, "Failed to allocate task container. Aborting load\n");
634  return -1;
635  }
636 
638 
639  return 0;
640 }
int ast_sched_start_thread(struct ast_sched_context *con)
Start a thread for processing scheduler entries.
Definition: sched.c:195
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
static struct ast_sched_context * scheduler_context
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition: cli.h:265
#define ast_log
Definition: astobj2.c:42
struct ast_sched_context * ast_sched_context_create(void)
Create a scheduler context.
Definition: sched.c:236
static struct ast_cli_entry cli_commands[]
#define LOG_ERROR
Definition: logger.h:285
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
Definition: astobj2.h:1310
#define TASK_BUCKETS
static struct ao2_container * tasks
Reject objects with duplicate keys in container.
Definition: astobj2.h:1192
void ast_sched_context_destroy(struct ast_sched_context *c)
destroys a schedule context
Definition: sched.c:269

◆ cli_show_tasks()

static char* cli_show_tasks ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 490 of file pjsip_scheduler.c.

References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_container_alloc_rbtree, ao2_container_count(), ao2_container_dup(), ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, AO2_ITERATOR_UNLINK, ao2_lock, ao2_ref, ao2_unlock, ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_localtime(), ast_sip_sched_task_get_next_run(), AST_SIP_SCHED_TASK_ONESHOT, ast_strftime(), ast_tv(), ast_tvadd(), ast_tvnow(), ast_tvzero(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, ast_sip_sched_task::flags, ast_sip_sched_task::interval, ast_sip_sched_task::is_running, ast_sip_sched_task::last_start, ast_sip_sched_task::name, NULL, regex(), ast_sip_sched_task::run_count, TIME_FORMAT, ast_cli_entry::usage, and ast_sip_sched_task::when_queued.

491 {
492  struct ao2_iterator iter;
493  struct ao2_container *sorted_tasks;
494  struct ast_sip_sched_task *schtd;
495  struct ast_tm tm;
496  char times_run[16];
497  char queued[32];
498  char last_start[32];
499  char next_start[32];
500  struct timeval now;
501  int using_regex = 0;
502  regex_t regex;
503 
504  switch (cmd) {
505  case CLI_INIT:
506  e->command = "pjsip show scheduled_tasks";
507  e->usage = "Usage: pjsip show scheduled_tasks [ like <pattern> ]\n"
508  " Show scheduled pjsip tasks\n";
509  return NULL;
510  case CLI_GENERATE:
511  return NULL;
512  }
513 
514  if (a->argc != 3 && a->argc != 5) {
515  return CLI_SHOWUSAGE;
516  }
517 
518  if (a->argc == 5) {
519  int regrc;
520  if (strcasecmp(a->argv[3], "like")) {
521  return CLI_SHOWUSAGE;
522  }
523  regrc = regcomp(&regex, a->argv[4], REG_EXTENDED | REG_ICASE | REG_NOSUB);
524  if (regrc) {
525  char err[256];
526  regerror(regrc, &regex, err, 256);
527  ast_cli(a->fd, "PJSIP Scheduled Tasks: Error: %s\n", err);
528  return CLI_FAILURE;
529  }
530  using_regex = 1;
531  }
532 
533  /* Get a sorted snapshot of the scheduled tasks */
535  ast_sip_sched_task_sort_fn, NULL);
536  if (!sorted_tasks) {
537  ast_cli(a->fd, "PJSIP Scheduled Tasks: Unable to allocate temporary container\n");
538  return CLI_FAILURE;
539  }
540  if (ao2_container_dup(sorted_tasks, tasks, 0)) {
541  ao2_ref(sorted_tasks, -1);
542  ast_cli(a->fd, "PJSIP Scheduled Tasks: Unable to sort temporary container\n");
543  return CLI_FAILURE;
544  }
545 
546  now = ast_tvnow();
547 
548  ast_localtime(&now, &tm, NULL);
549 
550  ast_cli(a->fd, "PJSIP Scheduled Tasks:\n\n");
551 
552  ast_cli(a->fd,
553  "<Task Name....................................> <Interval> <Times Run> <State>"
554  " <Queued....> <Last Start> <Next Start.....secs>\n"
555  "=============================================================================="
556  "===================================================\n");
557 
558  iter = ao2_iterator_init(sorted_tasks, AO2_ITERATOR_UNLINK);
559  for (; (schtd = ao2_iterator_next(&iter)); ao2_ref(schtd, -1)) {
560  int next_run_sec;
561  struct timeval next;
562 
563  ao2_lock(schtd);
564 
565  if (using_regex && regexec(&regex, schtd->name, 0, NULL, 0) == REG_NOMATCH) {
566  ao2_unlock(schtd);
567  continue;
568  }
569 
570  next_run_sec = ast_sip_sched_task_get_next_run(schtd) / 1000;
571  if (next_run_sec < 0) {
572  /* Scheduled task is now canceled */
573  ao2_unlock(schtd);
574  continue;
575  }
576  next = ast_tvadd(now, ast_tv(next_run_sec, 0));
577 
578  ast_localtime(&schtd->when_queued, &tm, NULL);
579  ast_strftime(queued, sizeof(queued), TIME_FORMAT, &tm);
580 
581  ast_localtime(&schtd->last_start, &tm, NULL);
582  ast_strftime(last_start, sizeof(last_start), TIME_FORMAT, &tm);
583 
584  ast_localtime(&next, &tm, NULL);
585  ast_strftime(next_start, sizeof(next_start), TIME_FORMAT, &tm);
586 
587  sprintf(times_run, "%d", schtd->run_count);
588 
589  ast_cli(a->fd, "%-46.46s %9d %9s %-5s %-12s %-12s %-12s %8d\n",
590  schtd->name,
591  schtd->interval / 1000,
592  schtd->flags & AST_SIP_SCHED_TASK_ONESHOT ? "oneshot" : times_run,
593  schtd->is_running ? "run" : "wait",
594  queued,
595  (ast_tvzero(schtd->last_start) || (schtd->flags & AST_SIP_SCHED_TASK_ONESHOT) ? "" : last_start),
596  next_start,
597  next_run_sec);
598  ao2_unlock(schtd);
599  }
600  if (using_regex) {
601  regfree(&regex);
602  }
603  ao2_iterator_destroy(&iter);
604  ast_cli(a->fd, "\nTotal Scheduled Tasks: %d\n\n", ao2_container_count(sorted_tasks));
605  ao2_ref(sorted_tasks, -1);
606 
607  return CLI_SUCCESS;
608 }
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
struct timeval last_start
const int argc
Definition: cli.h:160
struct ast_tm * ast_localtime(const struct timeval *timep, struct ast_tm *p_tm, const char *zone)
Timezone-independent version of localtime_r(3).
Definition: localtime.c:1739
int ast_tvzero(const struct timeval t)
Returns true if the argument is 0,0.
Definition: time.h:108
Definition: cli.h:152
struct timeval when_queued
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:150
#define ao2_unlock(a)
Definition: astobj2.h:730
#define NULL
Definition: resample.c:96
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
const int fd
Definition: cli.h:159
#define TIME_FORMAT
#define ao2_ref(o, delta)
Definition: astobj2.h:464
#define ao2_lock(a)
Definition: astobj2.h:718
const char *const * argv
Definition: cli.h:161
int ao2_container_dup(struct ao2_container *dest, struct ao2_container *src, enum search_flags flags)
Copy all object references in the src container into the dest container.
#define CLI_SHOWUSAGE
Definition: cli.h:45
enum ast_sip_scheduler_task_flags flags
struct timeval ast_tvadd(struct timeval a, struct timeval b)
Returns the sum of two timevals a + b.
Definition: extconf.c:2283
#define ao2_iterator_next(iter)
Definition: astobj2.h:1933
int ast_sip_sched_task_get_next_run(struct ast_sip_sched_task *schtd)
Gets the number of milliseconds until the next invocation.
#define CLI_FAILURE
Definition: cli.h:46
char * command
Definition: cli.h:186
static int regex(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
Definition: func_strings.c:948
int ast_strftime(char *buf, size_t len, const char *format, const struct ast_tm *tm)
Special version of strftime(3) that handles fractions of a second. Takes the same arguments as strfti...
Definition: localtime.c:2524
const char * usage
Definition: cli.h:177
#define CLI_SUCCESS
Definition: cli.h:44
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition: astobj2.h:1841
static struct ao2_container * tasks
struct timeval ast_tv(ast_time_t sec, ast_suseconds_t usec)
Returns a timeval from sec, usec.
Definition: time.h:226
#define ao2_container_alloc_rbtree(ao2_options, container_options, sort_fn, cmp_fn)
Definition: astobj2.h:1358
Generic container type.
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.

◆ push_to_serializer()

static int push_to_serializer ( const void *  data)
static

Definition at line 157 of file pjsip_scheduler.c.

References ao2_lock, ao2_t_ref, ao2_unlink, ao2_unlock, ast_log, ast_sip_push_task(), AST_SIP_SCHED_TASK_TRACK, ast_sip_sched_task::current_scheduler_id, ast_sip_sched_task::flags, ast_sip_sched_task::interval, LOG_DEBUG, ast_sip_sched_task::name, run_task(), and ast_sip_sched_task::serializer.

Referenced by ast_sip_schedule_task(), and run_task().

158 {
159  struct ast_sip_sched_task *schtd = (struct ast_sip_sched_task *)data;
160  int sched_id;
161 
162  ao2_lock(schtd);
163  sched_id = schtd->current_scheduler_id;
164  schtd->current_scheduler_id = -1;
165  ao2_unlock(schtd);
166  if (sched_id < 0) {
167  /* Task was cancelled while waiting on the lock */
168  return 0;
169  }
170 
171  if (schtd->flags & AST_SIP_SCHED_TASK_TRACK) {
172  ast_log(LOG_DEBUG, "Sched %p: Ready to run %s\n", schtd, schtd->name);
173  }
174  ao2_t_ref(schtd, +1, "Give ref to run_task()");
175  if (ast_sip_push_task(schtd->serializer, run_task, schtd)) {
176  /*
177  * Oh my. Have to cancel the scheduled item because we
178  * unexpectedly cannot run it anymore.
179  */
180  ao2_unlink(tasks, schtd);
181  ao2_lock(schtd);
182  schtd->interval = 0;
183  ao2_unlock(schtd);
184 
185  ao2_t_ref(schtd, -1, "Failed so release run_task() ref");
186  }
187 
188  return 0;
189 }
#define ao2_t_ref(o, delta, tag)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:463
Scheduler ID holder.
Definition: sched.c:70
#define ao2_unlock(a)
Definition: astobj2.h:730
#define LOG_DEBUG
Definition: logger.h:241
#define ast_log
Definition: astobj2.c:42
#define ao2_lock(a)
Definition: astobj2.h:718
#define ao2_unlink(container, obj)
Definition: astobj2.h:1598
int ast_sip_push_task(struct ast_taskprocessor *serializer, int(*sip_task)(void *), void *task_data)
Pushes a task to SIP servants.
Definition: res_pjsip.c:5138
enum ast_sip_scheduler_task_flags flags
static int run_task(void *data)
The scheduled task&#39;s events are tracked in the debug log.
Definition: res_pjsip.h:1829
static struct ao2_container * tasks
struct ast_taskprocessor * serializer

◆ run_task()

static int run_task ( void *  data)
static

Definition at line 80 of file pjsip_scheduler.c.

References ao2_cleanup, ao2_lock, ao2_unlink, ao2_unlock, ast_log, ast_samp2tv(), ast_sched_add(), AST_SIP_SCHED_TASK_DELAY, AST_SIP_SCHED_TASK_ONESHOT, AST_SIP_SCHED_TASK_TRACK, AST_SIP_SCHED_TASK_VARIABLE, ast_tvadd(), ast_tvdiff_ms(), ast_tvnow(), ast_sip_sched_task::interval, LOG_DEBUG, LOG_ERROR, push_to_serializer(), and RAII_VAR.

Referenced by push_to_serializer().

81 {
82  RAII_VAR(struct ast_sip_sched_task *, schtd, data, ao2_cleanup);
83  int res;
84  int delay;
85 
86  if (!schtd->interval) {
87  /* Task was cancelled while waiting to be executed by the serializer */
88  return -1;
89  }
90 
91  if (schtd->flags & AST_SIP_SCHED_TASK_TRACK) {
92  ast_log(LOG_DEBUG, "Sched %p: Running %s\n", schtd, schtd->name);
93  }
94  ao2_lock(schtd);
95  schtd->last_start = ast_tvnow();
96  schtd->is_running = 1;
97  ++schtd->run_count;
98  ao2_unlock(schtd);
99 
100  res = schtd->task(schtd->task_data);
101 
102  ao2_lock(schtd);
103  schtd->is_running = 0;
104  schtd->last_end = ast_tvnow();
105 
106  /*
107  * Don't restart if the task returned <= 0 or if the interval
108  * was set to 0 while the task was running
109  */
110  if ((schtd->flags & AST_SIP_SCHED_TASK_ONESHOT) || res <= 0 || !schtd->interval) {
111  schtd->interval = 0;
112  ao2_unlock(schtd);
113  ao2_unlink(tasks, schtd);
114  return -1;
115  }
116 
117  if (schtd->flags & AST_SIP_SCHED_TASK_VARIABLE) {
118  schtd->interval = res;
119  }
120 
121  if (schtd->flags & AST_SIP_SCHED_TASK_DELAY) {
122  delay = schtd->interval;
123  } else {
124  int64_t diff;
125 
126  /* Determine next periodic interval we need to expire. */
127  do {
128  schtd->next_periodic = ast_tvadd(schtd->next_periodic,
129  ast_samp2tv(schtd->interval, 1000));
130  diff = ast_tvdiff_ms(schtd->next_periodic, schtd->last_end);
131  } while (diff <= 0);
132  delay = diff;
133  }
134 
135  schtd->current_scheduler_id = ast_sched_add(scheduler_context, delay, push_to_serializer, schtd);
136  if (schtd->current_scheduler_id < 0) {
137  schtd->interval = 0;
138  ao2_unlock(schtd);
139  ast_log(LOG_ERROR, "Sched %p: Failed to reschedule task %s\n", schtd, schtd->name);
140  ao2_unlink(tasks, schtd);
141  return -1;
142  }
143 
144  ao2_unlock(schtd);
145  if (schtd->flags & AST_SIP_SCHED_TASK_TRACK) {
146  ast_log(LOG_DEBUG, "Sched %p: Rescheduled %s for %d ms\n", schtd, schtd->name,
147  delay);
148  }
149 
150  return 0;
151 }
static struct ast_sched_context * scheduler_context
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:150
#define ao2_unlock(a)
Definition: astobj2.h:730
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
Definition: time.h:98
#define LOG_DEBUG
Definition: logger.h:241
static int push_to_serializer(const void *data)
#define ast_log
Definition: astobj2.c:42
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
#define ao2_lock(a)
Definition: astobj2.h:718
struct timeval ast_samp2tv(unsigned int _nsamp, unsigned int _rate)
Returns a timeval corresponding to the duration of n samples at rate r. Useful to convert samples to ...
Definition: time.h:238
#define LOG_ERROR
Definition: logger.h:285
#define ao2_unlink(container, obj)
Definition: astobj2.h:1598
struct timeval ast_tvadd(struct timeval a, struct timeval b)
Returns the sum of two timevals a + b.
Definition: extconf.c:2283
The next invocation of the task is at last finish + interval.
Definition: res_pjsip.h:1822
int ast_sched_add(struct ast_sched_context *con, int when, ast_sched_cb callback, const void *data) attribute_warn_unused_result
Adds a scheduled event.
Definition: sched.c:565
The scheduled task&#39;s events are tracked in the debug log.
Definition: res_pjsip.h:1829
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
static struct ao2_container * tasks

◆ schtd_dtor()

static void schtd_dtor ( void *  data)
static

Definition at line 399 of file pjsip_scheduler.c.

References ao2_ref, ast_free, ast_log, AST_SIP_SCHED_TASK_DATA_AO2, AST_SIP_SCHED_TASK_DATA_FREE, AST_SIP_SCHED_TASK_TRACK, ast_taskprocessor_unreference(), ast_sip_sched_task::flags, LOG_DEBUG, ast_sip_sched_task::name, ast_sip_sched_task::serializer, and ast_sip_sched_task::task_data.

Referenced by ast_sip_schedule_task().

400 {
401  struct ast_sip_sched_task *schtd = data;
402 
403  if (schtd->flags & AST_SIP_SCHED_TASK_TRACK) {
404  ast_log(LOG_DEBUG, "Sched %p: Destructor %s\n", schtd, schtd->name);
405  }
406  if (schtd->flags & AST_SIP_SCHED_TASK_DATA_AO2) {
407  /* release our own ref, then release the callers if asked to do so */
408  ao2_ref(schtd->task_data, (schtd->flags & AST_SIP_SCHED_TASK_DATA_FREE) ? -2 : -1);
409  } else if (schtd->task_data && (schtd->flags & AST_SIP_SCHED_TASK_DATA_FREE)) {
410  ast_free(schtd->task_data);
411  }
413 }
#define LOG_DEBUG
Definition: logger.h:241
#define ast_log
Definition: astobj2.c:42
#define ao2_ref(o, delta)
Definition: astobj2.h:464
enum ast_sip_scheduler_task_flags flags
#define ast_free(a)
Definition: astmm.h:182
The scheduled task&#39;s events are tracked in the debug log.
Definition: res_pjsip.h:1829
void * ast_taskprocessor_unreference(struct ast_taskprocessor *tps)
Unreference the specified taskprocessor and its reference count will decrement.
struct ast_taskprocessor * serializer

Variable Documentation

◆ cli_commands

struct ast_cli_entry cli_commands[]
static
Initial value:
= {
{ .handler = cli_show_tasks , .summary = "Show pjsip scheduled tasks" ,},
}
static char * cli_show_tasks(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)

Definition at line 610 of file pjsip_scheduler.c.

◆ scheduler_context

struct ast_sched_context* scheduler_context
static

Definition at line 37 of file pjsip_scheduler.c.

◆ task_count

int task_count
static

Definition at line 39 of file pjsip_scheduler.c.

Referenced by ast_sip_schedule_task().

◆ tasks

struct ao2_container* tasks
static

Definition at line 38 of file pjsip_scheduler.c.