43 #include "asterisk/poll-compat.h"
52 static struct ast_heap *timing_interfaces;
59 static int timing_holder_cmp(
void *_h1,
void *_h2)
78 if (!funcs->timer_open ||
79 !funcs->timer_close ||
80 !funcs->timer_set_rate ||
82 !funcs->timer_get_event ||
83 !funcs->timer_get_max_rate ||
84 !funcs->timer_enable_continuous ||
85 !funcs->timer_disable_continuous ||
97 ast_heap_wrlock(timing_interfaces);
99 ast_heap_unlock(timing_interfaces);
109 ast_heap_wrlock(timing_interfaces);
111 ast_heap_unlock(timing_interfaces);
129 ast_heap_rdlock(timing_interfaces);
133 data = h->iface->timer_open();
141 h->iface->timer_close(data);
149 ast_heap_unlock(timing_interfaces);
156 handle->holder->iface->timer_close(handle->data);
163 return handle->holder->iface->timer_fd(handle->data);
168 return handle->holder->iface->timer_set_rate(handle->data, rate);
173 return handle->holder->iface->timer_ack(handle->data, quantity);
178 return handle->holder->iface->timer_enable_continuous(handle->data);
183 return handle->holder->iface->timer_disable_continuous(handle->data);
188 return handle->holder->iface->timer_get_event(handle->data);
193 return handle->holder->iface->timer_get_max_rate(handle->data);
198 return handle->holder->iface->name;
205 struct timeval start, end;
206 unsigned int test_rate = 50;
211 e->
usage =
"Usage: timing test <rate>\n"
212 " Test a timer with a specified rate, 50/sec by default.\n"
219 if (a->argc != 2 && a->argc != 3) {
220 return CLI_SHOWUSAGE;
225 if (sscanf(a->argv[2],
"%30u", &rate) == 1) {
228 ast_cli(a->fd,
"Invalid rate '%s', using default of %u\n", a->argv[2], test_rate);
232 ast_cli(a->fd,
"Attempting to test a timer with %u ticks per second.\n", test_rate);
235 ast_cli(a->fd,
"Failed to open timing fd\n");
239 ast_cli(a->fd,
"Using the '%s' timing module for this test.\n", timer->holder->iface->name);
247 struct pollfd pfd = {
249 .events = POLLIN | POLLPRI,
252 res = ast_poll(&pfd, 1, 100);
257 ast_cli(a->fd,
"Timer failed to acknowledge.\n");
262 ast_cli(a->fd,
"poll() timed out! This is bad.\n");
263 }
else if (errno != EAGAIN && errno != EINTR) {
264 ast_cli(a->fd,
"poll() returned error: %s\n", strerror(errno));
271 ast_cli(a->fd,
"It has been %" PRIi64
" milliseconds, and we got %d timer ticks\n",
278 AST_CLI_DEFINE(timing_test,
"Run a timing test"),
281 static void timing_shutdown(
void)
286 timing_interfaces = NULL;
void ast_timer_close(struct ast_timer *handle)
Close an opened timing handle.
unsigned int ast_timer_get_max_rate(const struct ast_timer *handle)
Get maximum rate supported for a timer.
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
Time-related functions and macros.
descriptor for a cli entry.
int ast_unregister_timing_interface(void *handle)
Unregister a previously registered timing interface.
struct ast_timer * ast_timer_open(void)
Open a timer.
struct ast_heap * ast_heap_destroy(struct ast_heap *h)
Destroy a max heap.
#define ast_cli_register_multiple(e, len)
Register multiple commands.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
const char * ast_timer_get_name(const struct ast_timer *handle)
Get name of timer in use.
#define ast_heap_push(h, elm)
Push an element on to a heap.
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
int ast_timing_init(void)
enum ast_timer_event ast_timer_get_event(const struct ast_timer *handle)
Retrieve timing event.
int ast_timer_enable_continuous(const struct ast_timer *handle)
Enable continuous mode.
int ast_timer_fd(const struct ast_timer *handle)
Get a poll()-able file descriptor for a timer.
#define ast_calloc(num, len)
A wrapper for calloc()
int ast_timer_disable_continuous(const struct ast_timer *handle)
Disable continuous mode.
int ast_timer_ack(const struct ast_timer *handle, unsigned int quantity)
Acknowledge a timer event.
Prototypes for public functions only of internal interest,.
#define ast_heap_create(init_height, cmp_fn, index_offset)
Create a max heap.
#define ast_module_unref(mod)
Release a reference to the module.
#define ast_module_running_ref(mod)
Hold a reference to the module if it is running.
int ast_timer_set_rate(const struct ast_timer *handle, unsigned int rate)
Set the timing tick rate.
void * ast_heap_remove(struct ast_heap *h, void *elm)
Remove a specific element from a heap.
Standard Command Line Interface.
void * ast_heap_peek(struct ast_heap *h, unsigned int index)
Peek at an element on a heap.
Asterisk module definitions.
Timing source management.