aboutsummaryrefslogtreecommitdiffstats
path: root/res/res_timing_pthread.c
diff options
context:
space:
mode:
authorrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2009-02-17 21:22:40 +0000
committerrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2009-02-17 21:22:40 +0000
commit590d768106d7dbe9e00c1888e6f59f8bfefb7645 (patch)
tree970a76c529a8b43ee7d90a826d405bbe41d54e2e /res/res_timing_pthread.c
parent4b22e504ec664a49e638795b8fc5b6953d2c4137 (diff)
Update the timing API to have better support for multiple timing interfaces.
1) Add module use count handling so that timing modules can be unloaded. 2) Implement unload_module() functions for the timing interface modules. 3) Allow multiple timing modules to be loaded, and use the one with the highest priority value. 4) Report which timing module is being use in the "timing test" CLI command. (closes issue #14489) Reported by: russell Review: http://reviewboard.digium.com/r/162/ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@176666 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'res/res_timing_pthread.c')
-rw-r--r--res/res_timing_pthread.c35
1 files changed, 18 insertions, 17 deletions
diff --git a/res/res_timing_pthread.c b/res/res_timing_pthread.c
index 0afe9c9bf..a45287588 100644
--- a/res/res_timing_pthread.c
+++ b/res/res_timing_pthread.c
@@ -23,11 +23,6 @@
* \brief pthread timing interface
*/
-/*** MODULEINFO
- <conflict>res_timing_timerfd</conflict>
- <conflict>res_timing_dahdi</conflict>
- ***/
-
#include "asterisk.h"
ASTERISK_FILE_VERSION(__FILE__, "$Revision$");
@@ -50,10 +45,12 @@ static int pthread_timer_set_rate(int handle, unsigned int rate);
static void pthread_timer_ack(int handle, unsigned int quantity);
static int pthread_timer_enable_continuous(int handle);
static int pthread_timer_disable_continuous(int handle);
-static enum ast_timing_event pthread_timer_get_event(int handle);
+static enum ast_timer_event pthread_timer_get_event(int handle);
static unsigned int pthread_timer_get_max_rate(int handle);
-static struct ast_timing_functions pthread_timing_functions = {
+static struct ast_timing_interface pthread_timing = {
+ .name = "pthread",
+ .priority = 0, /* use this as a last resort */
.timer_open = pthread_timer_open,
.timer_close = pthread_timer_close,
.timer_set_rate = pthread_timer_set_rate,
@@ -255,10 +252,10 @@ static int pthread_timer_disable_continuous(int handle)
return 0;
}
-static enum ast_timing_event pthread_timer_get_event(int handle)
+static enum ast_timer_event pthread_timer_get_event(int handle)
{
struct pthread_timer *timer;
- enum ast_timing_event res = AST_TIMING_EVENT_EXPIRED;
+ enum ast_timer_event res = AST_TIMING_EVENT_EXPIRED;
if (!(timer = find_timer(handle, 0))) {
return res;
@@ -491,22 +488,26 @@ static int load_module(void)
return AST_MODULE_LOAD_DECLINE;
}
- return (timing_funcs_handle = ast_install_timing_functions(&pthread_timing_functions)) ?
+ return (timing_funcs_handle = ast_register_timing_interface(&pthread_timing)) ?
AST_MODULE_LOAD_SUCCESS : AST_MODULE_LOAD_DECLINE;
}
static int unload_module(void)
{
-#if 0
- /* XXX code to stop the timing thread ... */
+ int res;
- ast_uninstall_timing_functions(timing_funcs_handle);
- ao2_ref(pthread_timers, -1);
-#endif
+ ast_mutex_lock(&timing_thread.lock);
+ timing_thread.stop = 1;
+ ast_cond_signal(&timing_thread.cond);
+ ast_mutex_unlock(&timing_thread.lock);
+ pthread_join(timing_thread.thread, NULL);
- /* This module can not currently be unloaded. No use count handling is being done. */
+ if (!(res = ast_unregister_timing_interface(timing_funcs_handle))) {
+ ao2_ref(pthread_timers, -1);
+ pthread_timers = NULL;
+ }
- return -1;
+ return res;
}
AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "pthread Timing Interface");