summaryrefslogtreecommitdiff
path: root/res/res_timing_dahdi.c
diff options
context:
space:
mode:
authorJoshua Colp <jcolp@digium.com>2014-02-07 20:01:45 +0000
committerJoshua Colp <jcolp@digium.com>2014-02-07 20:01:45 +0000
commite8e2f91bbac77ca50dddc4a496512475990a8764 (patch)
treefdbb590820a386771e01916e9dbd7809bd187232 /res/res_timing_dahdi.c
parent5fd63e2d0beeae4e118a7567716b586899166090 (diff)
timing: Improve performance for most timing implementations.
This change allows timing implementation data to be stored directly on the timer itself thus removing the requirement for many implementations to do a container lookup for the same information. This means that API calls into timing implementations can directly access the information they need instead of having to find it. Review: https://reviewboard.asterisk.org/r/3175/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@407749 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'res/res_timing_dahdi.c')
-rw-r--r--res/res_timing_dahdi.c80
1 files changed, 57 insertions, 23 deletions
diff --git a/res/res_timing_dahdi.c b/res/res_timing_dahdi.c
index 6298253b7..7af71f141 100644
--- a/res/res_timing_dahdi.c
+++ b/res/res_timing_dahdi.c
@@ -45,14 +45,15 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$");
static void *timing_funcs_handle;
-static int dahdi_timer_open(void);
-static void dahdi_timer_close(int handle);
-static int dahdi_timer_set_rate(int handle, unsigned int rate);
-static int dahdi_timer_ack(int handle, unsigned int quantity);
-static int dahdi_timer_enable_continuous(int handle);
-static int dahdi_timer_disable_continuous(int handle);
-static enum ast_timer_event dahdi_timer_get_event(int handle);
-static unsigned int dahdi_timer_get_max_rate(int handle);
+static void *dahdi_timer_open(void);
+static void dahdi_timer_close(void *data);
+static int dahdi_timer_set_rate(void *data, unsigned int rate);
+static int dahdi_timer_ack(void *data, unsigned int quantity);
+static int dahdi_timer_enable_continuous(void *data);
+static int dahdi_timer_disable_continuous(void *data);
+static enum ast_timer_event dahdi_timer_get_event(void *data);
+static unsigned int dahdi_timer_get_max_rate(void *data);
+static int dahdi_timer_fd(void *data);
static struct ast_timing_interface dahdi_timing = {
.name = "DAHDI",
@@ -65,27 +66,48 @@ static struct ast_timing_interface dahdi_timing = {
.timer_disable_continuous = dahdi_timer_disable_continuous,
.timer_get_event = dahdi_timer_get_event,
.timer_get_max_rate = dahdi_timer_get_max_rate,
+ .timer_fd = dahdi_timer_fd,
};
-static int dahdi_timer_open(void)
+struct dahdi_timer {
+ int fd;
+};
+
+static void *dahdi_timer_open(void)
{
- return open("/dev/dahdi/timer", O_RDWR);
+ struct dahdi_timer *timer;
+
+ if (!(timer = ast_calloc(1, sizeof(*timer)))) {
+ return NULL;
+ }
+
+ if ((timer->fd = open("/dev/dahdi/timer", O_RDWR)) < 0) {
+ ast_log(LOG_ERROR, "Failed to create dahdi timer: %s\n", strerror(errno));
+ ast_free(timer);
+ return NULL;
+ }
+
+ return timer;
}
-static void dahdi_timer_close(int handle)
+static void dahdi_timer_close(void *data)
{
- close(handle);
+ struct dahdi_timer *timer = data;
+
+ close(timer->fd);
+ ast_free(timer);
}
-static int dahdi_timer_set_rate(int handle, unsigned int rate)
+static int dahdi_timer_set_rate(void *data, unsigned int rate)
{
+ struct dahdi_timer *timer = data;
int samples;
/* DAHDI timers are configured using a number of samples,
* based on an 8 kHz sample rate. */
samples = (unsigned int) roundf((8000.0 / ((float) rate)));
- if (ioctl(handle, DAHDI_TIMERCONFIG, &samples)) {
+ if (ioctl(timer->fd, DAHDI_TIMERCONFIG, &samples)) {
ast_log(LOG_ERROR, "Failed to configure DAHDI timing fd for %u sample timer ticks\n",
samples);
return -1;
@@ -94,31 +116,36 @@ static int dahdi_timer_set_rate(int handle, unsigned int rate)
return 0;
}
-static int dahdi_timer_ack(int handle, unsigned int quantity)
+static int dahdi_timer_ack(void *data, unsigned int quantity)
{
- return ioctl(handle, DAHDI_TIMERACK, &quantity) ? -1 : 0;
+ struct dahdi_timer *timer = data;
+
+ return ioctl(timer->fd, DAHDI_TIMERACK, &quantity) ? -1 : 0;
}
-static int dahdi_timer_enable_continuous(int handle)
+static int dahdi_timer_enable_continuous(void *data)
{
+ struct dahdi_timer *timer = data;
int flags = 1;
- return ioctl(handle, DAHDI_TIMERPING, &flags) ? -1 : 0;
+ return ioctl(timer->fd, DAHDI_TIMERPING, &flags) ? -1 : 0;
}
-static int dahdi_timer_disable_continuous(int handle)
+static int dahdi_timer_disable_continuous(void *data)
{
+ struct dahdi_timer *timer = data;
int flags = -1;
- return ioctl(handle, DAHDI_TIMERPONG, &flags) ? -1 : 0;
+ return ioctl(timer->fd, DAHDI_TIMERPONG, &flags) ? -1 : 0;
}
-static enum ast_timer_event dahdi_timer_get_event(int handle)
+static enum ast_timer_event dahdi_timer_get_event(void *data)
{
+ struct dahdi_timer *timer = data;
int res;
int event;
- res = ioctl(handle, DAHDI_GETEVENT, &event);
+ res = ioctl(timer->fd, DAHDI_GETEVENT, &event);
if (res) {
event = DAHDI_EVENT_TIMER_EXPIRED;
@@ -133,11 +160,18 @@ static enum ast_timer_event dahdi_timer_get_event(int handle)
}
}
-static unsigned int dahdi_timer_get_max_rate(int handle)
+static unsigned int dahdi_timer_get_max_rate(void *data)
{
return 1000;
}
+static int dahdi_timer_fd(void *data)
+{
+ struct dahdi_timer *timer = data;
+
+ return timer->fd;
+}
+
#define SEE_TIMING "For more information on Asterisk timing modules, including ways to potentially fix this problem, please see https://wiki.asterisk.org/wiki/display/AST/Timing+Interfaces\n"
static int dahdi_test_timer(void)