diff options
author | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-06-13 12:45:50 +0000 |
---|---|---|
committer | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-06-13 12:45:50 +0000 |
commit | a720d9e5c87511d93077f86d4fac2ed3d563bc06 (patch) | |
tree | 857ccefe1322ae0e28d63bf209482b762087b97d /main/timing.c | |
parent | fdd4115f4d6f5212f782b32d5fc5a5cd4dc3dd23 (diff) |
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: http://svn.digium.com/svn/asterisk/trunk@122523 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main/timing.c')
-rw-r--r-- | main/timing.c | 74 |
1 files changed, 47 insertions, 27 deletions
diff --git a/main/timing.c b/main/timing.c index d87ebcc15..6de1a29dd 100644 --- a/main/timing.c +++ b/main/timing.c @@ -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; } |