Merge changes from timing branch

- Convert chan_iax2 to use the timing API
 - Convert usage of timing in the core to use the timing API instead of
   using DAHDI directly
 - Make a change to the timing API to add the set_rate() function
 - change the timing core to use a rwlock
 - merge a timing implementation, res_timing_dahdi

Basic testing was successful using res_timing_dahdi


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@122523 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Russell Bryant
2008-06-13 12:45:50 +00:00
parent a68a160b75
commit b6457ecf4c
8 changed files with 319 additions and 161 deletions

View File

@@ -30,7 +30,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/timing.h"
#include "asterisk/lock.h"
AST_MUTEX_DEFINE_STATIC(lock);
AST_RWLOCK_DEFINE_STATIC(lock);
static struct ast_timing_functions timer_funcs;
@@ -38,6 +38,7 @@ void *ast_install_timing_functions(struct ast_timing_functions *funcs)
{
if (!funcs->timer_open ||
!funcs->timer_close ||
!funcs->timer_set_rate ||
!funcs->timer_ack ||
!funcs->timer_get_event ||
!funcs->timer_enable_continuous ||
@@ -45,94 +46,113 @@ void *ast_install_timing_functions(struct ast_timing_functions *funcs)
return NULL;
}
ast_mutex_lock(&lock);
ast_rwlock_wrlock(&lock);
if (timer_funcs.timer_open) {
ast_mutex_unlock(&lock);
ast_rwlock_unlock(&lock);
ast_log(LOG_NOTICE, "Multiple timing modules are loaded. You should only load one.\n");
return NULL;
}
timer_funcs = *funcs;
ast_mutex_unlock(&lock);
ast_rwlock_unlock(&lock);
return &timer_funcs;
}
void ast_uninstall_timing_functions(void *handle)
{
ast_mutex_lock(&lock);
ast_rwlock_wrlock(&lock);
if (handle != &timer_funcs) {
ast_mutex_unlock(&lock);
ast_rwlock_unlock(&lock);
return;
}
memset(&timer_funcs, 0, sizeof(timer_funcs));
ast_mutex_unlock(&lock);
ast_rwlock_unlock(&lock);
}
int ast_timer_open(unsigned int rate)
int ast_timer_open(void)
{
int timer;
ast_mutex_lock(&lock);
ast_rwlock_rdlock(&lock);
if (!timer_funcs.timer_open) {
ast_mutex_unlock(&lock);
ast_rwlock_unlock(&lock);
return -1;
}
timer = timer_funcs.timer_open(rate);
timer = timer_funcs.timer_open();
ast_mutex_unlock(&lock);
ast_rwlock_unlock(&lock);
return timer;
}
void ast_timer_close(int timer)
{
ast_mutex_lock(&lock);
ast_rwlock_rdlock(&lock);
if (!timer_funcs.timer_close) {
ast_mutex_unlock(&lock);
ast_rwlock_unlock(&lock);
return;
}
timer_funcs.timer_close(timer);
ast_mutex_unlock(&lock);
ast_rwlock_unlock(&lock);
}
int ast_timer_set_rate(int handle, unsigned int rate)
{
int res;
ast_rwlock_rdlock(&lock);
if (!timer_funcs.timer_set_rate) {
ast_rwlock_unlock(&lock);
return -1;
}
res = timer_funcs.timer_set_rate(handle, rate);
ast_rwlock_unlock(&lock);
return res;
}
void ast_timer_ack(int handle, unsigned int quantity)
{
ast_mutex_lock(&lock);
ast_rwlock_rdlock(&lock);
if (!timer_funcs.timer_ack) {
ast_mutex_unlock(&lock);
ast_rwlock_unlock(&lock);
return;
}
timer_funcs.timer_ack(handle, quantity);
ast_mutex_unlock(&lock);
ast_rwlock_unlock(&lock);
}
int ast_timer_enable_continuous(int handle)
{
int result;
ast_mutex_lock(&lock);
ast_rwlock_rdlock(&lock);
if (!timer_funcs.timer_enable_continuous) {
ast_mutex_unlock(&lock);
ast_rwlock_unlock(&lock);
return -1;
}
result = timer_funcs.timer_enable_continuous(handle);
ast_mutex_unlock(&lock);
ast_rwlock_unlock(&lock);
return result;
}
@@ -141,16 +161,16 @@ int ast_timer_disable_continous(int handle)
{
int result;
ast_mutex_lock(&lock);
ast_rwlock_rdlock(&lock);
if (!timer_funcs.timer_disable_continuous) {
ast_mutex_unlock(&lock);
ast_rwlock_unlock(&lock);
return -1;
}
result = timer_funcs.timer_disable_continuous(handle);
ast_mutex_unlock(&lock);
ast_rwlock_unlock(&lock);
return result;
}
@@ -159,16 +179,16 @@ enum ast_timing_event ast_timer_get_event(int handle)
{
enum ast_timing_event result;
ast_mutex_lock(&lock);
ast_rwlock_rdlock(&lock);
if (!timer_funcs.timer_get_event) {
ast_mutex_unlock(&lock);
ast_rwlock_unlock(&lock);
return -1;
}
result = timer_funcs.timer_get_event(handle);
ast_mutex_unlock(&lock);
ast_rwlock_unlock(&lock);
return result;
}