summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorzuul <zuul@gerrit.asterisk.org>2016-09-19 18:03:13 -0500
committerGerrit Code Review <gerrit2@gerrit.digium.api>2016-09-19 18:03:13 -0500
commit34461b89ace3742056100bb226a3c0c2d90ca5ff (patch)
treef41a1601fe75274abd1937e490fe41d3c9977b19 /main
parent0bd4398b8a0f104d1375ab8ba93f29042147ddd0 (diff)
parente96448e991d0c9285baa413c73a336189f6c5ba5 (diff)
Merge "asterisk.c: When astcanary dies on linux, reset priority on all threads." into 13
Diffstat (limited to 'main')
-rw-r--r--main/asterisk.c42
1 files changed, 41 insertions, 1 deletions
diff --git a/main/asterisk.c b/main/asterisk.c
index 7f58f9113..69f1d7140 100644
--- a/main/asterisk.c
+++ b/main/asterisk.c
@@ -1863,6 +1863,46 @@ static void set_icon(char *text)
fprintf(stdout, "\033]1;%s\007", text);
}
+/*! \brief Set priority on all known threads. */
+static int set_priority_all(int pri)
+{
+#if !defined(__linux__)
+ /* The non-linux version updates the entire process prio. */
+ return ast_set_priority(pri);
+#elif defined(LOW_MEMORY)
+ ast_log(LOG_WARNING, "Unable to enumerate all threads to update priority\n");
+ return ast_set_priority(pri);
+#else
+ struct thread_list_t *cur;
+ struct sched_param sched;
+ char const *policy_str;
+ int policy;
+
+ memset(&sched, 0, sizeof(sched));
+ if (pri) {
+ policy = SCHED_RR;
+ policy_str = "realtime";
+ sched.sched_priority = 10;
+ } else {
+ policy = SCHED_OTHER;
+ policy_str = "regular";
+ sched.sched_priority = 0;
+ }
+ if (sched_setscheduler(getpid(), policy, &sched)) {
+ ast_log(LOG_WARNING, "Unable to set %s thread priority on main thread\n", policy_str);
+ return -1;
+ }
+ ast_verb(1, "Setting %s thread priority on all threads\n", policy_str);
+ AST_RWLIST_RDLOCK(&thread_list);
+ AST_RWLIST_TRAVERSE(&thread_list, cur, list) {
+ /* Don't care about the return value. It should work. */
+ sched_setscheduler(cur->lwp, policy, &sched);
+ }
+ AST_RWLIST_UNLOCK(&thread_list);
+ return 0;
+#endif
+}
+
/*! \brief We set ourselves to a high priority, that we might pre-empt
* everything else. If your PBX has heavy activity on it, this is a
* good thing.
@@ -3832,7 +3872,7 @@ static void *canary_thread(void *unused)
"He's kicked the bucket. He's shuffled off his mortal coil, "
"run down the curtain, and joined the bleeding choir invisible!! "
"THIS is an EX-CANARY. (Reducing priority)\n");
- ast_set_priority(0);
+ set_priority_all(0);
pthread_exit(NULL);
}