static int load_module(void) { if (dahdi_test_timer()) { return AST_MODULE_LOAD_DECLINE; } return (timing_funcs_handle = ast_register_timing_interface(&dahdi_timing)) ? AST_MODULE_LOAD_SUCCESS : AST_MODULE_LOAD_DECLINE; }
/*! * \brief Load the module * * Module loading including tests for configuration or dependencies. * This function can return AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_DECLINE, * or AST_MODULE_LOAD_SUCCESS. If a dependency or environment variable fails * tests return AST_MODULE_LOAD_FAILURE. If the module can not load the * configuration file or other non-critical problem return * AST_MODULE_LOAD_DECLINE. On success return AST_MODULE_LOAD_SUCCESS. */ static int load_module(void) { if (!(timing_funcs_handle = ast_register_timing_interface(&kqueue_timing))) { return AST_MODULE_LOAD_DECLINE; } AST_TEST_REGISTER(test_kqueue_timing); return AST_MODULE_LOAD_SUCCESS; }
static int load_module(void) { if (!(kqueue_timers = ao2_container_alloc(563, kqueue_timer_hash, kqueue_timer_cmp))) { return AST_MODULE_LOAD_DECLINE; } if (!(timing_funcs_handle = ast_register_timing_interface(&kqueue_timing))) { ao2_ref(kqueue_timers, -1); return AST_MODULE_LOAD_DECLINE; } AST_TEST_REGISTER(test_kqueue_timing); return AST_MODULE_LOAD_SUCCESS; }
static int load_module(void) { if (!(pthread_timers = ao2_container_alloc(PTHREAD_TIMER_BUCKETS, pthread_timer_hash, pthread_timer_cmp))) { return AST_MODULE_LOAD_DECLINE; } if (init_timing_thread()) { ao2_ref(pthread_timers, -1); pthread_timers = NULL; return AST_MODULE_LOAD_DECLINE; } return (timing_funcs_handle = ast_register_timing_interface(&pthread_timing)) ? AST_MODULE_LOAD_SUCCESS : AST_MODULE_LOAD_DECLINE; }
static int load_module(void) { int fd; /* Make sure we support the necessary clock type */ if ((fd = timerfd_create(CLOCK_MONOTONIC, 0)) < 0) { ast_log(LOG_ERROR, "timerfd_create() not supported by the kernel. Not loading.\n"); return AST_MODULE_LOAD_DECLINE; } close(fd); if (!(timerfd_timers = ao2_container_alloc(TIMERFD_TIMER_BUCKETS, timerfd_timer_hash, timerfd_timer_cmp))) { return AST_MODULE_LOAD_DECLINE; } if (!(timing_funcs_handle = ast_register_timing_interface(&timerfd_timing))) { ao2_ref(timerfd_timers, -1); return AST_MODULE_LOAD_DECLINE; } return AST_MODULE_LOAD_SUCCESS; }
static int timerfd_timer_enable_continuous(void *data) { struct timerfd_timer *timer = data; int res; static const struct itimerspec continuous_timer = { .it_value.tv_nsec = 1L, }; ao2_lock(timer); if (timer->is_continuous) { /*It's already in continous mode, no need to do * anything further */ ao2_unlock(timer); return 0; } res = timerfd_settime(timer->fd, 0, &continuous_timer, &timer->saved_timer); timer->is_continuous = 1; ao2_unlock(timer); return res; } static int timerfd_timer_disable_continuous(void *data) { struct timerfd_timer *timer = data; int res; ao2_lock(timer); if (!timer->is_continuous) { /* No reason to do anything if we're not * in continuous mode */ ao2_unlock(timer); return 0; } res = timerfd_settime(timer->fd, 0, &timer->saved_timer, NULL); timer->is_continuous = 0; memset(&timer->saved_timer, 0, sizeof(timer->saved_timer)); ao2_unlock(timer); return res; } static enum ast_timer_event timerfd_timer_get_event(void *data) { struct timerfd_timer *timer = data; enum ast_timer_event res; ao2_lock(timer); if (timer->is_continuous) { res = AST_TIMING_EVENT_CONTINUOUS; } else { res = AST_TIMING_EVENT_EXPIRED; } ao2_unlock(timer); return res; } static unsigned int timerfd_timer_get_max_rate(void *data) { return TIMERFD_MAX_RATE; } static int timerfd_timer_fd(void *data) { struct timerfd_timer *timer = data; return timer->fd; } static int load_module(void) { int fd; /* Make sure we support the necessary clock type */ if ((fd = timerfd_create(CLOCK_MONOTONIC, 0)) < 0) { ast_log(LOG_ERROR, "timerfd_create() not supported by the kernel. Not loading.\n"); return AST_MODULE_LOAD_DECLINE; } close(fd); if (!(timing_funcs_handle = ast_register_timing_interface(&timerfd_timing))) { return AST_MODULE_LOAD_DECLINE; } return AST_MODULE_LOAD_SUCCESS; }