summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
Diffstat (limited to 'main')
-rw-r--r--main/autochan.c6
-rw-r--r--main/config_options.c2
-rw-r--r--main/sched.c45
3 files changed, 44 insertions, 9 deletions
diff --git a/main/autochan.c b/main/autochan.c
index 7da249a13..c1e8b83f3 100644
--- a/main/autochan.c
+++ b/main/autochan.c
@@ -51,7 +51,7 @@ struct ast_autochan *ast_autochan_setup(struct ast_channel *chan)
autochan->chan = ast_channel_ref(chan);
- ast_channel_lock(autochan->chan);
+ ast_channel_lock(autochan->chan); /* autochan is still private, no need for ast_autochan_channel_lock() */
AST_LIST_INSERT_TAIL(ast_channel_autochans(autochan->chan), autochan, list);
ast_channel_unlock(autochan->chan);
@@ -64,7 +64,7 @@ void ast_autochan_destroy(struct ast_autochan *autochan)
{
struct ast_autochan *autochan_iter;
- ast_channel_lock(autochan->chan);
+ ast_autochan_channel_lock(autochan);
AST_LIST_TRAVERSE_SAFE_BEGIN(ast_channel_autochans(autochan->chan), autochan_iter, list) {
if (autochan_iter == autochan) {
AST_LIST_REMOVE_CURRENT(list);
@@ -73,7 +73,7 @@ void ast_autochan_destroy(struct ast_autochan *autochan)
}
}
AST_LIST_TRAVERSE_SAFE_END;
- ast_channel_unlock(autochan->chan);
+ ast_autochan_channel_unlock(autochan);
autochan->chan = ast_channel_unref(autochan->chan);
diff --git a/main/config_options.c b/main/config_options.c
index 5da310fd8..db99a441d 100644
--- a/main/config_options.c
+++ b/main/config_options.c
@@ -1346,7 +1346,7 @@ static int int_handler_fn(const struct aco_option *opt, struct ast_variable *var
*/
static int uint_handler_fn(const struct aco_option *opt, struct ast_variable *var, void *obj) {
unsigned int *field = (unsigned int *)(obj + opt->args[0]);
- unsigned int flags = PARSE_INT32 | opt->flags;
+ unsigned int flags = PARSE_UINT32 | opt->flags;
int res = 0;
if (opt->flags & PARSE_IN_RANGE) {
res = opt->flags & PARSE_DEFAULT ?
diff --git a/main/sched.c b/main/sched.c
index f851670af..222c69183 100644
--- a/main/sched.c
+++ b/main/sched.c
@@ -83,6 +83,14 @@ struct sched {
/*! The ID that has been popped off the scheduler context's queue */
struct sched_id *sched_id;
struct timeval when; /*!< Absolute time event should take place */
+ /*!
+ * \brief Tie breaker in case the when is the same for multiple entries.
+ *
+ * \note The oldest expiring entry in the scheduler heap goes first.
+ * This is possible when multiple events are scheduled to expire at
+ * the same time by internal coding.
+ */
+ unsigned int tie_breaker;
int resched; /*!< When to reschedule */
int variable; /*!< Use return value from callback to reschedule */
const void *data; /*!< Data */
@@ -107,6 +115,8 @@ struct ast_sched_context {
ast_mutex_t lock;
unsigned int eventcnt; /*!< Number of events processed */
unsigned int highwater; /*!< highest count so far */
+ /*! Next tie breaker in case events expire at the same time. */
+ unsigned int tie_breaker;
struct ast_heap *sched_heap;
struct sched_thread *sched_thread;
/*! The scheduled task that is currently executing */
@@ -213,9 +223,17 @@ int ast_sched_start_thread(struct ast_sched_context *con)
return 0;
}
-static int sched_time_cmp(void *a, void *b)
+static int sched_time_cmp(void *va, void *vb)
{
- return ast_tvcmp(((struct sched *) b)->when, ((struct sched *) a)->when);
+ struct sched *a = va;
+ struct sched *b = vb;
+ int cmp;
+
+ cmp = ast_tvcmp(b->when, a->when);
+ if (!cmp) {
+ cmp = b->tie_breaker - a->tie_breaker;
+ }
+ return cmp;
}
struct ast_sched_context *ast_sched_context_create(void)
@@ -442,11 +460,28 @@ int ast_sched_wait(struct ast_sched_context *con)
*/
static void schedule(struct ast_sched_context *con, struct sched *s)
{
- ast_heap_push(con->sched_heap, s);
+ size_t size;
+
+ size = ast_heap_size(con->sched_heap);
- if (ast_heap_size(con->sched_heap) > con->highwater) {
- con->highwater = ast_heap_size(con->sched_heap);
+ /* Record the largest the scheduler heap became for reporting purposes. */
+ if (con->highwater <= size) {
+ con->highwater = size + 1;
}
+
+ /* Determine the tie breaker value for the new entry. */
+ if (size) {
+ ++con->tie_breaker;
+ } else {
+ /*
+ * Restart the sequence for the first entry to make integer
+ * roll over more unlikely.
+ */
+ con->tie_breaker = 0;
+ }
+ s->tie_breaker = con->tie_breaker;
+
+ ast_heap_push(con->sched_heap, s);
}
/*! \brief